wildcard when setting directories

11 Ansichten (letzte 30 Tage)
Kathleen Hupfeld
Kathleen Hupfeld am 22 Feb. 2018
Beantwortet: Arvind Narayanan am 2 Mär. 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 Kommentar
per isakson
per isakson am 22 Feb. 2018
Bearbeitet: per isakson am 22 Feb. 2018
subjID is a cell array, but need to be a character row.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Arvind Narayanan
Arvind Narayanan am 2 Mär. 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

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by