Creating ramp signal from -1 to 1
7 views (last 30 days)
Show older comments
Sheung Man Keung
on 27 Jul 2021
Edited: Yongjian Feng
on 27 Jul 2021
I am trying to create a linear line from y = -1 to 1 from x = 0 to 2000 but my code is creating the linear line from y = 0 to 1. Where am I going wrong with this?
y = 167
t = 60
x = linspace(0, t, y*t);
rampIdx = 2000;
s4 = zeros(1, length(x));
s4(rampIdx+1:end)=1;
s4(1:rampIdx+1) = -1;
s4(1:rampIdx+1) = (1:rampIdx)/rampIdx
0 Comments
Accepted Answer
Yongjian Feng
on 27 Jul 2021
Edited: Yongjian Feng
on 27 Jul 2021
First there is an error in the last line:
y = 167;
t = 60;
x = linspace(0, t, y*t);
rampIdx = 2000;
s4 = zeros(1, length(x));
s4(rampIdx+1:end)=1;
s4(1:rampIdx) = -1;
z = linspace(-rampIdx, rampIdx, rampIdx);
s4(1:rampIdx) = z/rampIdx;
plot(x, s4)
4 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!