Save figures in a subfolder after 2 for loops?

I have created 2 for loop. The first is for 5 subjects. The second one is for 4 measurements. Then I have a code to save a figure for each subject per test. But now it stores each figure in my main folder 'Data_examen'. I want to create a subfolder for each subject, so 'Subject1'...'Subject5'. And each subfolder must contain the 4 figures of their measurements... I have no idea how to do this. But this is my code I already have:
for welke_pp=1:aantal_pp %for 5 subjects
...
end
for i_testen=1:length(data_stair_rise)-1 %for 4 measurements
folder = 'Data_examen' %my main folder (where I want to create my subfolders...)
% Create a PNG filename.
pngFileName = sprintf('3Dplot_subject%d_trial%d.png', welke_pp, i_testen);
fullFileName = fullfile(folder, pngFileName);
saveas(gcf,fullFileName); %save current opened figure

 채택된 답변

Yona
Yona 2014년 12월 24일
편집: Yona 2014년 12월 24일

0 개 추천

use mkdir to create a folder and change the folder name you save on to the relevant folder.
and you can use cd, dir and other command to see or move to other folders.

댓글 수: 4

Sam
Sam 2014년 12월 24일
euhm?
add something like:
NewFolder=['subject' num2str(welke_pp)];
mkdir NewFolder
fullFileName = fullfile([folder '\\' NewFolder], pngFileName);
If the folder exist you don't need to creat it so the last line is enough (if you don't know if the folder exist you can use exist function in if statements.
Sam
Sam 2014년 12월 24일
Thanks a lot! But it only works if I already have created a folder. Is it possible that Matlab makes the folder for me?
mkdir create a folder. just try in command to create a folder:
mkdir('TestFolder')

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

질문:

Sam
2014년 12월 24일

댓글:

2014년 12월 24일

Community Treasure Hunt

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

Start Hunting!

Translated by