Saving a set of figures in a loop

  • Thread starter Thread starter mikeph
  • Start date Start date
  • Tags Tags
    Loop Set
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 2K views
mikeph
Messages
1,229
Reaction score
18
Hi,

I have a loop which produces a series of figures, specified by the iteration number.

For example the loop, simplified, is:

for i = 1:10
[code generating X and Y]
figure(i)
plot(X,Y)
end

So running it produces 10 images. I'd like to save them automatically, for future comparison.

How would I do this?

I've tried:

saveas(i,sprintf('%s.jpg',num2str(i)))

to save figure 1 as 1.jpg, and so on, but it's just giving me a blank white image.

Thanks for any help.
 
Physics news on Phys.org
maybe try:
Code:
print -djpeg filename