How to plot results from each iteration of a for loop SEPARATELY

105 ビュー (過去 30 日間)
Joshua Pretorius
Joshua Pretorius 2021 年 11 月 16 日
コメント済み: Dave B 2021 年 11 月 16 日
Hi all,
I would like to know how i can plot results obtained through a for loop on seperate plots. I understand that i can plot each itteration result on the same plot, but i need to plot each itteration on a seperate plot so they can be closely analysed.
Any help would be great, thanks !

採用された回答

Dave B
Dave B 2021 年 11 月 16 日
You can do this in separate windows using the figure function:
for i = 1:3
figure
plot(rand(1,10))
end
In separate axes within a figure using nexttile (requires 2019b or later, for earlier versions see subplot)
figure;
tiledlayout('flow');
for i = 1:10
nexttile
plot(rand(1,10))
end
(or if you want them in a specific grid shape):
figure
t=tiledlayout(5,2);
for i = 1:10
nexttile
plot(rand(1,10))
end
Or you can try stackedplot if you don't have too many and you can put them all into a table or matrix:
figure
stackedplot(rand(100,4))
  2 件のコメント
Joshua Pretorius
Joshua Pretorius 2021 年 11 月 16 日
Thanks Dave, works perfectly !
is there a way to generate different titles for each plot generated, for the first method you suggested ? so it would generate titles like Figure1, Figure 2 etc for each plot
Dave B
Dave B 2021 年 11 月 16 日
yep, you can use the title command with any of these methods. There are surprsingly many approaches to appending a number onto a word (Figure 1), but the easiest in my opinion is to use strings like this:
for i = 1:3
figure
plot(rand(1,10))
title("Figure " + i)
end

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

その他の回答 (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