How to plot results from each iteration of a for loop SEPARATELY
39 views (last 30 days)
Show older comments
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 !
0 Comments
Accepted Answer
Dave B
on 16 Nov 2021
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 Comments
Dave B
on 16 Nov 2021
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
More Answers (0)
See Also
Categories
Find more on Annotations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!