How to save multiple plots in one folder ?

90 vues (au cours des 30 derniers jours)
SUSHMA MB
SUSHMA MB le 5 Juin 2017
Commenté : Naif Alsalem le 13 Nov 2022
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 commentaire
Stephen23
Stephen23 le 6 Juin 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:
  • generate names: use sprintf and fullfile.
  • read names: use dir and fullfile.
You can also find some examples with my FEX submission natsortfiles:

Connectez-vous pour commenter.

Réponse acceptée

KSSV
KSSV le 5 Juin 2017
Modifié(e) : KSSV le 5 Juin 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 commentaires
KSSV
KSSV le 13 Nov 2022
That gives you path. You can print it out on screen and check.
Naif Alsalem
Naif Alsalem le 13 Nov 2022
Many thanks @KSSV

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur File Operations dans Help Center et File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by