wildcard when setting directories

10 次查看(过去 30 天)
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 个评论
per isakson
per isakson 2018-2-22
编辑:per isakson 2018-2-22
subjID is a cell array, but need to be a character row.

请先登录,再进行评论。

回答(1 个)

Arvind Narayanan
Arvind Narayanan 2018-3-2
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

类别

Help CenterFile Exchange 中查找有关 Multidimensional Arrays 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by