![](https://www.mathworks.com/matlabcentral/images/broken_image.png)
Need help making a stairs graph
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Samious
am 22 Mär. 2014
Kommentiert: Image Analyst
am 22 Mär. 2014
Hi can anyone tell me how to make a stair graph? For example, I have two y values, the fist is 3 when x is from 0 to 4, the second is -3 when x is from 4 to 8.
Since the total length is 8, I put
x=8;
y=??;
but what do I need to put for y? when there are two difference values but I need them on the same graph.
stairs(x,y)
Best Regards
Samious
0 Kommentare
Akzeptierte Antwort
Image Analyst
am 22 Mär. 2014
Try this:
x = 0 : 8
y = [3,3,3,3, -3,-3,-3,-3,-3];
stairs(x, y, 'bo-', 'LineWidth', 3);
ylim([-4, 4]);
grid on;
![](https://www.mathworks.com/matlabcentral/images/broken_image.png)
2 Kommentare
Image Analyst
am 22 Mär. 2014
Here's some more general code to handle that:
amplitude = 4.3;
b = 8;
a = 3;
x = [0 : a, a : b]
y = [amplitude * ones(1, a+1), -amplitude * ones(1, length(a:b))]
stairs(x, y, 'bo-', 'LineWidth', 3);
ylim([-5, 5]);
grid on;
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Directed Graphs finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!