wildcard when setting directories

조회 수: 11 (최근 30일)
Kathleen Hupfeld
Kathleen Hupfeld 2018년 2월 22일
답변: Arvind Narayanan 2018년 3월 2일
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