Automatic saving a figure as an image file in Matl

2019-05-07 08:11发布

I'm creating 49 figures in Matlab, they are all created automatically one after the other. I want them to also automatically be saved as .tif or .jpg images with names corresponding to their figure number. Can I do it? And if so,how?

the code for the creation of the figures is:

for num_picture=0:48
  ...
  figure (num_picture+1)
  imshow (screen_im)
end

The ... part is where all the calculations of screen_im are.

I want those images in order to create a movie from them, If there is a way where I can create the movie automatically form Matlab, it would be good also, actually it will be better.

2条回答
别忘想泡老子
2楼-- · 2019-05-07 08:41

To answer your second question, have a look at avifile(). However, I've had better luck saving frames individually (compression quality issues if I recall correctly).

To save individual frames, you can use imwrite() or print() with a -dpng or similar option. From there, use sprintf() to generate a filename with your frame number in it, and you've got most of what you need. You'll need some sort of movie editor program (VideoMach, etc.) to turn those frames into a movie if you don't use Matlab's avifile(), however.

查看更多
啃猪蹄的小仙女
3楼-- · 2019-05-07 08:49

You can save current figure into a file with PRINT of SAVEAS command generating the filename using loop counter:

saveas(sprintf('img%d.tif',num_picture))

or

 print('-dtiff','-r300',sprintf('img%d.tif',num_picture))
查看更多
登录 后发表回答