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일

0 개 추천

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

Stephen23
Stephen23 2017년 6월 5일
@KSSV: it is good advice to use one figure. Keep in mind though:
  • do NOT use the name path, because it is already an important inbuilt function.
  • much better to use fullfile rather than concatenating strings.
what if i want to save it with the filename of the file that i am taking the information from
Stephen23
Stephen23 2022년 9월 14일
@Firas Guechchati: Use DIR and FILEPARTS.
Naif Alsalem
Naif Alsalem 2022년 11월 13일
What is the filesep in path = [path,filesep,myfolder] ;?
KSSV
KSSV 2022년 11월 13일
That gives you path. You can print it out on screen and check.
Naif Alsalem
Naif Alsalem 2022년 11월 13일
Many thanks @KSSV

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Printing and Saving에 대해 자세히 알아보기

태그

질문:

2017년 6월 5일

댓글:

2022년 11월 13일

Community Treasure Hunt

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

Start Hunting!

Translated by