MATLAB Answers

Need help for saveas function for saving multiple figures

125 views (last 30 days)
Sarah
Sarah on 17 Apr 2012
Commented: Pradeep on 24 Nov 2013
Hey guys,
Need some help with the saveas function. How can I save multiple figures that are being generated by a for loop? For example, this is what I have so far:
for k = 1:10
figure(k);
plot(foo)
saveas(k,'???')
How can I change my string at every iteration? I need the string to be descriptive with respect to the content of the figure.

  0 Comments

Sign in to comment.

Accepted Answer

Jessica Lam
Jessica Lam on 17 Apr 2012
should be saveas not save
saveas(gca,temp)

  2 Comments

Jessica Lam
Jessica Lam on 17 Apr 2012
try that one again=)
hope it works
for k = 1:10 figure(k); plot(foo); temp=['fig',num2str(k),'.png']; saveas(gca,temp); end

Sign in to comment.

More Answers (1)

Jessica Lam
Jessica Lam on 17 Apr 2012
for k = 1:10 figure(k); plot(foo); temp=['fig',num2str(k),'.png']; save(gca,temp); end

  3 Comments

Sarah
Sarah on 17 Apr 2012
hmmm, this is not working, it is telling me that the argument in save must be a string...
Image Analyst
Image Analyst on 17 Apr 2012
See the FAQ: http://matlab.wikia.com/wiki/FAQ#How_do_I_save_my_figure.2C_axes.2C_or_image.3F_I.27m_having_trouble_with_the_built_in_MATLAB_functions.
Pradeep
Pradeep on 24 Nov 2013
Use saveas in place of save
for k = 1:10 figure(k); plot(foo); temp=['fig',num2str(k),'.png']; saveas(gca,temp); end
The code worked for me and I think it should work for you too.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!