Reputation: 1037
I'm new to Matlab and I faced this problem: I wrote a ramp function , it is work correctly if I plot ramp(t-1),ramp(t-2),ramp(t-3).... but it doesn't work when I'm trying to plot ramp(t),ramp(t+1),ramp(t+2)....
here is my code:
function [ y ] = ramp(x)
y(x<0)=0;
s = (abs(x(length(x)))+abs(x(1)))/length(x);% x(2)-x(1) or x(i)-x(i-1), EX:{1,1.2,1.4}s=0.2
y(x>=0)= 0:s:x(length(x));
end
Upvotes: 0
Views: 105
Reputation: 8459
I can't see reproduce any errors using your code, but here is a different way of doing the same thing.
function [ y ] = ramp(x)
y=zeros(size(x));
y(x>=0)=linspace(0,x(end),length(x(x>=0)))
end
Upvotes: 2