フィルターのクリア

Need help making a stairs graph

3 ビュー (過去 30 日間)
Samious
Samious 2014 年 3 月 22 日
コメント済み: Image Analyst 2014 年 3 月 22 日
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

採用された回答

Image Analyst
Image Analyst 2014 年 3 月 22 日
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;
  2 件のコメント
Samious
Samious 2014 年 3 月 22 日
編集済み: Samious 2014 年 3 月 22 日
just a quick question though, if x is an unknown number, eg (b), what do I need to put in y? (point a is in the middle)
3, between 0 and a, -3 between a and b
will this work?
x=0:b y=[3*(b-a),-3*(a+(b-a))]?
Image Analyst
Image Analyst 2014 年 3 月 22 日
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;

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeDirected Graphs についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by