MATLAB: How to save all the generated figures automatically from a Matlab code to a specified folder in the computer

figurespecified folder

Hi, I have a script file from which I am expected to generate about 3000 figures through FOR loop iteration (synthetic figures generated through the code of matlab). Now as the outputs are figures , I want them all to save in one folder automatically. (basically i want to create a file path and save all the figures automatically.) It is not possible to save every figure one by one as it will be very time consuming and nearly impossible. Can anyone say how to do it? Thank you in advance very much.

Best Answer

Inside the loop, after Figure generated, here k loop counts
fig=figure
destination='D:\Kalyan Works\Matlab Work\folder_name\fig';
print([destination,num2str(k),'.dpng']);
close(fig)
It save all figure name as fig1,fig2....