Can anyone help me?
2 views (last 30 days)
Show older comments
Each run of my program plots a figure. Can anyone help me to run the program 50 times and save each figure into a file?
1 Comment
Accepted Answer
Geoff Hayes
on 2 Jan 2015
Edited: Geoff Hayes
on 2 Jan 2015
Mini - do you want to save the figure to a fig file or to some other data type? If the former, then you would use savefig, and if the latter you would use saveas. As for running your program fifty times, you could do something like this
numIters = 50;
for k=1:numIters
% close the current figure
close gcf;
% call your program that plots a figure
% save the current figure to file
filename = sprintf('myFigure%d.fig',k);
savefig(gcf,filename);
end
Note how we create a unique filename on each iteration of the for loop. You can modify the above to use the saveas function instead, or to specify a different file name and/or folder for that file.
Note how we use gcf which gets the current figure handle which will be the one that your program just created.
2 Comments
More Answers (0)
See Also
Categories
Find more on Printing and Saving 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!