Try to store data in 2 for loops

2 views (last 30 days)
Sam
Sam on 23 Dec 2014
Commented: Sam on 23 Dec 2014
I've got 2 for loops. The first for loop is for 5 subjects. The second for loop is for 4 measurements. I want to store a figure for subject1, trial1; subject1, trial2; subject1, trial3,...subject5, trial 4.
for welke_pp=1:aantal_pp %for loop for 5 subjects
...
for i_testen=1:length(data_stair_rise)-1 %for loop for 4 measurements
...
folder = 'Data_examen'
pngFileName = sprintf('plot_subject1_trial%d.png', i_testen);
fullFileName = fullfile(folder, pngFileName);
saveas(gcf,fullFileName);
As you can see, at the end op 'pngFileName' I typed only 'i_testen'. So Matlab only stores the figures for trial1,2,3 and 4. But now I want to store the trials for each subject. How do I do this?

Accepted Answer

Geoff Hayes
Geoff Hayes on 23 Dec 2014
Sam - use the subject number in our output image name. Something like
pngFileName = sprintf('plot_subject%d_trial%d.png', welke_pp, i_testen);
Now, 20 files should be created, four for each subject.

More Answers (0)

Categories

Find more on Programming in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!