Matlab saves pictures in batches

Matlab saves pictures in batches

gossip

I haven't written anything for more than a month. During this period of time, I was busy writing small papers, and I also had some small problems in my relationship, which was very annoying. I didn't even bother to write. But now I can do it again! ! ! , We must keep learning and keep updating! ! !
This is something I came into contact with when I first started studying, and I haven't summed it up. Now turn it out and look at it to make a summary.

Use saveas to save pictures in batches in a loop

Gossip less:

clc
clear;
mkdir('C:\Users\Ryj\Desktop\picture');%创建文件夹
for i=1:20
    x=1:i;
    y1=x.*2;
    figure;
    plot(x,'g+','LineWidth',6.0);hold on;
    plot(x,y1,'g+','LineWidth',6.0);
    h1=gcf ;
    saveas(h1, ['C:\Users\Ryj\Desktop\picture\', num2str(i), '.jpg']);
end
  • After creating the folder, generate the image in the loop, get the handle of the current image, and use the saveas function to specify the handle, path, name and format.
  • After the program runs, you will get the images obtained by the corresponding cycle in the folder you created. Of course, the current program will display all the figures. If you have a lot of cycles, you can research to make the figures not displayed. Or close it by yourself after displaying (I guess you know how to do it).
    insert image description here
    After the loop image is saved, you can make animation! ! !

Guess you like

Origin blog.csdn.net/ONERYJHHH/article/details/116451206