For loop based on files names and locations

Hi,
Im trying to run first level analysis for many participants. I got the code from spm12 for one participants and now I'm trying to run for-loop to repeat the analysis to all other participants. I'd really appriciate that if I could have any suggestions about how to define for-loop based on the directory and the names of the files (the files names are different). The data is organized in one folder that includes a folder for each participant and that folder includes the file (along with other files).
Thank you!

Answers (2)

% get the folder contents
d = dir() ;
% remove all files (isdir property is 0)
dfolders = d([d(:).isdir]) ;
% remove '.' and '..'
dfolders = dfolders(~ismember({dfolders(:).name},{'.','..'})) ;
% loop for each folder
for i = 1:length(dfolders)
dfolders.name
end

Categories

Find more on Programming in Help Center and File Exchange

Products

Release

R2022b

Asked:

on 15 Dec 2022

Commented:

on 15 Dec 2022

Community Treasure Hunt

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

Start Hunting!