- generate names: use sprintf and fullfile.
 - read names: use dir and fullfile.
 
How to save multiple plots in one folder ?
    18 views (last 30 days)
  
       Show older comments
    
 for k = 1:10 
        figure(k); 
         plot(foo); 
         temp=['fig',num2str(k),'.png']; 
           saveas(gca,temp); 
       end
In this particular code i have 10 figures. How can i save all these figures in one single folder.
1 Comment
  Stephen23
      
      
 on 6 Jun 2017
				How to read multiple files is explained extensively in the documentation, on this forum, and in the wiki:
etc
The first thing to decide is if you want to generate the file names, or if you want to read the names of existing files:
You can also find some examples with my FEX submission natsortfiles:
Accepted Answer
  KSSV
      
      
 on 5 Jun 2017
        
      Edited: KSSV
      
      
 on 5 Jun 2017
  
      Note that, it is not needed to use figure(k), you can simply use only one figure and update it every time and save.
path = pwd ;   % mention your path 
myfolder = 'myfolder' ;   % new folder name 
folder = mkdir([path,filesep,myfolder]) ;
path  = [path,filesep,myfolder] ;
for k = 1:10
    figure(k);
    plot(rand(1,10));
    temp=[path,filesep,'fig',num2str(k),'.png'];
    saveas(gca,temp);
end
6 Comments
More Answers (0)
See Also
Categories
				Find more on File Operations in Help Center and File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!