wildcard when setting directories

10 views (last 30 days)
Kathleen Hupfeld
Kathleen Hupfeld on 22 Feb 2018
Answered: Arvind Narayanan on 2 Mar 2018
I want to set a directory path to use later in my code. However, each subject has a different folder name in their folder hierarchy: e.g., the full path to one person's folder hierarchy = 'C:\Users\APK-User\Documents\baseline\pp\3001\s001\2010\S001\con001.nii'
but the full path to another person's = 'C:\Users\APK-User\Documents\baseline\pp\3002\s002\2012\S002\con001.nii'
What could I do to have MatLab skip over the s002\2012\S002 portion of each person's path? Is there wildcard syntax I could use here? I couldn't get any combination I tried to work:
As an example, I want to be able to enter any subject in a subjID object array:
subjID={'3001'}
and then create their data path:
data_path = ['C:\Users\APK-User\Documents\baseline\pp\',subjID,'\','/s*','\','/2*','\','\S*'];
(& then I'm using SPM to select their .nii file:
a = spm_select('ExtFPList', fullfile(data_path),'^.*\.nii$');
The above syntax for data path doesn't work/doesn't skip over the file names properly. How could I get MatLab to do this?
  1 Comment
per isakson
per isakson on 22 Feb 2018
Edited: per isakson on 22 Feb 2018
subjID is a cell array, but need to be a character row.

Sign in to comment.

Answers (1)

Arvind Narayanan
Arvind Narayanan on 2 Mar 2018
Hi Kathleen,
The variable subjID above is a cell array. If you would like to loop over its elements and use SPM to select the files, you can place your code inside a for loop with iterator i and refer to each element of subjID as
subjID{i}
If you would like to return a comma-separated list of the elements of subjID, use this notation
subjID{:}
Please refer to the documentation on working with cell arrays for more information: https://in.mathworks.com/help/releases/R2016b/matlab/matlab_prog/access-data-in-a-cell-array.html
Thanks,
Arvind

Categories

Find more on Multidimensional Arrays in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!