Can I use 'for' loop to save multiple plots?

1 view (last 30 days)
I would like to create a 3D animation from a set of plots. The data set has 1000 points and I would like to plot 100 points in each figure and then automatically save it from 'saveas' command. Then I can just make a GIF by joining them. But how do I write the program to save the figures as fig1, fig2, fig3... by giving the number as a variable?

Accepted Answer

Guillaume
Guillaume on 2 Mar 2015
Use sprintf to create your filename:
for plotnumber = 1:10
%code for plotting
%hplot = ....
saveas(hplot, fullfile(folder, sprintf('fig%02d.gif', plotnumber)));
end
  3 Comments
Guillaume
Guillaume on 2 Mar 2015
I'm not sure what you're asking. The code you've posted does what you want already (except first plot is named 'fig01.jpg' which makes more sense).
RAVI LAKSHMANAN
RAVI LAKSHMANAN on 6 Feb 2020
Hi Guillaume, if the number of plots is unknown, how'd the for loop change? like here you have mentioned for 10p plots?

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Performance 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!