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

116 次查看(过去 30 天)
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 CenterFile Exchange 中查找有关 Title 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by