multiple cumulative subplots in while loop

1 回表示 (過去 30 日間)
Marius Mandela Make
Marius Mandela Make 2015 年 4 月 8 日
コメント済み: Kaelan Lockhart 2019 年 5 月 24 日
I want to plot several subplots within a loop. for example (This is just sample code, not the real one)
s(1)=0; x(1)=2; y(1)=3; hold on while(s(end)<500 x(end+1)=x(end)+1; y(end+1)=y(end)+x(end); s(end+1)=y(end)*x(end)+4; subplot(2,1,1) plot(x(end),y(end),'.') subplot(2,1,2) plot(x(end),s(end),'.') end
I only get the last point. However, if I write hold on while .... ... plot(x(end),y(end),'.') plot(x(end),s(end),'.') end I get the two on the same plot which is not what I want. I want thm on different subplots.

採用された回答

Debarati Banerjee
Debarati Banerjee 2015 年 4 月 13 日
You can use the 'hold on' command after plotting a set of data. The modified code is working as expected:
clear all;
figure
s(1)=0;
x(1)=2;
y(1)=3;
while(s(end)<500)
x(end+1)=x(end)+1;
y(end+1)=y(end)+x(end);
s(end+1)=y(end)*x(end)+4;
subplot(2,1,1)
plot(x(end),y(end),'.')
hold on
subplot(2,1,2)
plot(x(end),s(end),'.')
hold on
end
  2 件のコメント
Marius Mandela Make
Marius Mandela Make 2015 年 4 月 13 日
Cheers!!!!! It works :D
Kaelan Lockhart
Kaelan Lockhart 2019 年 5 月 24 日
How can you set the axis and graph titles outside of this loop?

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by