Saving a set of figures in a loop

  • Thread starter Thread starter mikeph
  • Start date Start date
  • Tags Tags
    Loop Set
Click For Summary
The discussion centers around automating the saving of figures generated in a loop within a programming environment. The user is attempting to save each figure produced by the loop using the command "saveas(i,sprintf('%s.jpg',num2str(i)))", but encounters an issue where the saved images appear blank. A suggested solution is to use the command "print -djpeg filename" to properly save the figures. This indicates a need for correct syntax and method when saving visual outputs in programming to ensure that the images retain their content.
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
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K