hold on for double plots in one loop

30 ビュー (過去 30 日間)
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 11 月 5 日
コメント済み: ME 2019 年 11 月 5 日
I am making two plots in a for loop one after an other. When the loop goes for the next i, I need to hold on the plot becaue I want to plot x1 and y1 of the i=1 to i=n in one axis but because there is an other plot after it, I do not know how to do that so that x1 and y1 of i=1 to n are plotted in one figure and x2 and y2 of i=1 to n are plotted in an nother figure.
For i=1:n
do some calc.
figure
plot(x1,y1)
if I hold on here, the next figure may have be plotted in the first one. But I need to have figures of i=1 to n plotted in one axis.
figure
plot(x2,y2)
end
  1 件のコメント
darova
darova 2019 年 11 月 5 日
IF you want to plot in different figure
figure(1)
figure(2)

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

回答 (2 件)

Takumi
Takumi 2019 年 11 月 5 日
編集済み: Takumi 2019 年 11 月 5 日
Try changing the plot target by referring to the link below.

ME
ME 2019 年 11 月 5 日
You just need to move the figure command or you’ll get two new figure windows. This would be something like:
figure
for i=1:n
do some calc.
plot(x1,y1)
hold on
plot(x2,y2)
end
or alternatively put both of the plotting commands into one:
plot(x1,y1,x2,y2)
  2 件のコメント
Zeynab Mousavikhamene
Zeynab Mousavikhamene 2019 年 11 月 5 日
編集済み: Zeynab Mousavikhamene 2019 年 11 月 5 日
@ME thanks but it was not answer to my question. I said in the question, I want to have TWO plots one is for x1 and y1 and the other one is for x2 and y2. For x1 and y1 of ALL i from 1 to n I want to plot x1 and y1 on the same figure and for ALL i from 1 to n I want to plot x2 and y2 on an other figure.
ME
ME 2019 年 11 月 5 日
Apologies, I think I see what you mean now. That just shows I shouldn't answer questions before a morning coffee!
I think this should do what you want:
for i=1:n
do some calc.
figure(1); hold on;
plot(x1,y1)
figure(2); hold on;
plot(x2,y2)
end

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

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by