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

 Akzeptierte Antwort

Yongjian Feng
Yongjian Feng am 27 Jul. 2021
Bearbeitet: Yongjian Feng am 27 Jul. 2021

0 Stimmen

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 Kommentare

Sheung Man Keung
Sheung Man Keung am 27 Jul. 2021
Thanks but the line still isn't linear going from y = -1 to 1.
Yongjian Feng
Yongjian Feng am 27 Jul. 2021
Modified. Please try again.
Sheung Man Keung
Sheung Man Keung am 27 Jul. 2021
Thanks but it is not exactly what I am looking for. I have attached an image of what I am looking for.
Yongjian Feng
Yongjian Feng am 27 Jul. 2021
Your boundary overlapped. Fixed again.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Produkte

Version

R2018a

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by