フィルターのクリア

Open and closed dots for endpoint

6 ビュー (過去 30 日間)
GMDI
GMDI 2019 年 9 月 26 日
コメント済み: GMDI 2019 年 10 月 10 日
Hi, I have a P matrix from where I want to draw a figure withstepfunction.PNG open and closed dots for endpoints (piecewise step function). I tried following:
P=[0 2
1 4
2 6
3 8
4 10
5 12
6 14
7 16
8 18
9 20
10 22
];
figure
stairs(P(:,1),P(:,2))
If I use stairs function, then I get staircase plot. But I want open and closed dots for endpoints. Something like below:
[0, 1) 2
[1, 2) 4
[2, 3) 6
[3, 4) 8
[4, 5) 10
[5, 6) 12
[6, 7) 14
[7, 8) 16
[8,9) 18
[9,10) 20
[10,10] 22
Please see attahced figure. I am expecting something like this.
Can anyone please suggest me how to plot this piecewise step function?
Thanks in advance.

採用された回答

Gaurav Garg
Gaurav Garg 2019 年 9 月 30 日
Hi,
You could refer to the below code:
P=[0 2
1 4
2 6
3 8
4 10
5 12
6 14
7 16
8 18
9 20
10 22
];
for i=1:10
plot([P(i,1),P(i+1,1)],[P(i,2),P(i,2)],'b');
hold on;
h1=plot(P(i,1),P(i,2),'bo');
set(h1,'markerfacecolor',get(h1,'color'))
% plot([P(i+1,1),P(i+1,1)],[P(i,2),P(i+1,2)])
hold on;
plot(P(i+1,1),P(i,2),'bo')
hold on
end
Here, we break the single stairs function into parts and plot each line using plot function. Then, we plot blue circles on the respective points. Finally, we connect all the lines and obtain the final desired graph.
  1 件のコメント
GMDI
GMDI 2019 年 10 月 10 日
Thanks. It helps a lot... :)

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by