i have created the the code below but still getting some errors that i cannot identify..
function k=step(t)
k = t>=0;
function k = ramp(t)
if t >= 0
k=t;
else
t<0
k=0;
end
t=-5:5;
f = zeros(size(t));
for x = 1:length(t)
f(t)= (5*ramp(t+3))- ramp(t+1) - (3.*ramp(t))+ (5*ramp(t-1)) + (3*step(t-2));
end
plot(t,f)
anyone can help please?
thanks in advance
Change the assignment from f(t) on the left hand side to f(x) on the left hand
side.
Also, I would point out that your ramp function is equivalent to max(0,t) . If
you were to change it to that, then both step() and ramp() would be vectorized
and you would then not need a loop to calculate your f.
yes i identified this mistake but still getting this error ..
??? In an assignment A(I) = B, the number of elements in B and
I must be the same.
Error in ==> rampstep at 7
f(x)= (5.*ramp(t+3))- ramp(t+1) - (3.*ramp(t))+ (5.*ramp(t-1)) +
(3.*step(t-2));
> yes i identified this mistake but still getting this error ..
>
> ??? In an assignment A(I) = B, the number of elements in B and
> I must be the same.
>
> Error in ==> rampstep at 7
> f(x)= (5.*ramp(t+3))- ramp(t+1) - (3.*ramp(t))+ (5.*ramp(t-1)) +
> (3.*step(t-2));
All the "t" on the right hand side should be "x".