フィルターのクリア

Plot on different figures during a loop

441 ビュー (過去 30 日間)
Nicolas
Nicolas 2011 年 7 月 28 日
コメント済み: Michael George 2021 年 1 月 29 日
Hi,
I'm extracting from different files some data that have ot plot on the same plot, I use a loop like
figure, hold on
for j=1:m
s=load(fileA{j});
t=load(fileB{j});
plot (t(:,1),t(:,2),'-r+')
end
I'd like to plot t(:,1),t(:,2) on figure 1, and for example t(:,1),t(:,3) on another figure. Is it possible to do it in the same loop?
thanks for your help
n

採用された回答

the cyclist
the cyclist 2011 年 7 月 28 日
Yes. When you call the figure() command, call it with an input argument:
>> figure(1)
>> figure(2)
Then, before you do the particular plotting command, call figure() again, using the input argument that you want to plot to:
>> figure(1)
>> plot(1:10)
>> figure(2)
>> plot(2:11)
When the figure number already exists, it makes that figure current.
You might want to read "doc figure", "doc gcf", and "doc hold" to make sure you don't overwrite the plot that is already there in that figure.
  3 件のコメント
Hitesh Luthra
Hitesh Luthra 2016 年 8 月 27 日
Is the same thing possible with gscatter () ?
the cyclist
the cyclist 2016 年 8 月 28 日
Yes

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

その他の回答 (2 件)

Paulo Silva
Paulo Silva 2011 年 7 月 28 日
just get the handles from those axes and use them as first argument in the plot
figure
hax1=axes
figure
hax2=axes
plot (hax1,t(:,1),t(:,2),'-r+')
plot (hax2,t(:,1),t(:,3),'-r+')
  1 件のコメント
Michael George
Michael George 2021 年 1 月 29 日
This is elegant as it doesn't require the extra figure function call every time! For looping and making animations, this is a faster approach. Just hand plot the axes handle to plot on. Thanks for this answer!

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


Kehinde OROLU
Kehinde OROLU 2011 年 7 月 28 日
Use this instead:
for j=1:m
s=load(fileA{j});
t=load(fileB{j});
for i=2:size(t,2)
figure(i),plot(t(:,1),t(:,i),'-r+')
hold on
end
end
hold off
  1 件のコメント
Nicolas
Nicolas 2011 年 7 月 29 日
Thanks for the idea, I wrote something like that to plot the two different files
for j=1:m
s=load(fileA{j});
t=load(fileB{j});
for i=2:size(t,2)
figure(i),plot(t(:,1),t(:,i),'-r+')
hold on
end
for k=2:size(s:2)
figure(i+k), plot(s(:,1),t(:,i),'-r+')
hold on
end
end
hold off

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

カテゴリ

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