How to save multiple plots in one folder ?

111 次查看(过去 30 天)
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 个评论
Stephen23
Stephen23 2017-6-6
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:

请先登录,再进行评论。

采纳的回答

KSSV
KSSV 2017-6-5
编辑:KSSV 2017-6-5
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 个评论
KSSV
KSSV 2022-11-13
That gives you path. You can print it out on screen and check.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 File Operations 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by