Saving a set of figures in a loop

  • Thread starter Thread starter mikeph
  • Start date Start date
  • Tags Tags
    Loop Set
Click For Summary
SUMMARY

The discussion focuses on automating the saving of figures generated in a loop using MATLAB. The user attempts to save figures using the command saveas(i,sprintf('%s.jpg',num2str(i))), but encounters issues with blank images. A suggested solution is to utilize the print -djpeg filename command to correctly save the figures in JPEG format. This approach ensures that the generated plots are saved as intended without resulting in blank outputs.

PREREQUISITES
  • Familiarity with MATLAB programming language
  • Understanding of figure generation and plotting in MATLAB
  • Knowledge of file formats, specifically JPEG
  • Basic understanding of loops in programming
NEXT STEPS
  • Research the print function in MATLAB for saving figures
  • Explore MATLAB's figure properties and settings for better output control
  • Learn about batch processing in MATLAB for automating repetitive tasks
  • Investigate alternative file formats supported by MATLAB for figure saving
USEFUL FOR

This discussion is beneficial for MATLAB users, data analysts, and researchers who need to automate the saving of graphical outputs generated in loops for further analysis or presentation.

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
3K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 9 ·
Replies
9
Views
5K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 4 ·
Replies
4
Views
4K