DSPRelated.com
Forums

Help with this matlab program

Started by mailtojayatus May 14, 2003
Hi

I am trying to generate a gaussian monocycle using matlab. And i have
the formula for that but the program gives me an error that
"Subscript indices must either be real positive integers or logicals"

for t=0.1e-9:0.01e-9:1e-9
s-9/7;
a(t)=(1-(t/s-3.5)^2);
b(t)=exp(-0.5*(t/s-3.5)^2);
p(t)=a(t)*b(t)
end
plot (t,p)

Please help me with this program.

Thank you,

Jay Shah



Hi!
Jay,

When you write a(t) (or b(t) or p(t)) on left side of
your assignment statement, it takes that as an array.
And index for array cannot be a floating number, while
t in this case is floating number...
Change the program as follows and it will work.

====================================
k = 0;
for t=0.1e-9:0.01e-9:1e-9
s-9/7;
k = k+1;
a(k) = (1-(t/s-3.5)^2);
b(k) = exp(-0.5*(t/s-3.5)^2);
p(k) = a(t)*b(t)
end

plot (t,p)
====================================

Regards,
Kaushik.

--- mailtojayatus <> wrote:
> Hi
>
> I am trying to generate a gaussian monocycle using
> matlab. And i have
> the formula for that but the program gives me an
> error that
> "Subscript indices must either be real positive
> integers or logicals"
>
> for t=0.1e-9:0.01e-9:1e-9
> s-9/7;
> a(t)=(1-(t/s-3.5)^2);
> b(t)=exp(-0.5*(t/s-3.5)^2);
> p(t)=a(t)*b(t)
> end
> plot (t,p)
>
> Please help me with this program.
>
> Thank you,
>
> Jay Shah >


__________________________________


>From: "mailtojayatus" <>
>To:
>Subject: [matlab] Help with this matlab program
>Date: Wed, 14 May 2003 14:15:34 -0000
>
>Hi
>
>I am trying to generate a gaussian monocycle using matlab. And i have
>the formula for that but the program gives me an error that
>"Subscript indices must either be real positive integers or logicals"
Dear Jay Shah

You confused the indices with the value that you need for your calculs it
very easy to
do it in other way, like :
t1 is the values that you nead, and t is the indice for your vector
a(t),b(t) and p(t).
try this :

s = 1e-9/7;
t1 = 0.1e-9:0.01e-9:1e-9;
for t = 1:length(t1);
a(t) = (1-(t1(t)/s-3.5)^2);
b(t) = exp(-0.5*(t1(t)/s-3.5)^2);
p(t) = a(t)*b(t);
end
plot(t1,p)
take care

Jaber EL HADAD
for t=0.1e-9:0.01e-9:1e-9
> s-9/7;
> a(t)=(1-(t/s-3.5)^2);
> b(t)=exp(-0.5*(t/s-3.5)^2);
> p(t)=a(t)*b(t)
>end
>plot (t,p)
>
>Please help me with this program.
>
>Thank you,
>
>Jay Shah

_________________________________________________________________
Charla con tus amigos en lea mediante MSN Messenger:
http://messenger.yupimsn.com/