selecting file which name only differs at the end
6 ビュー (過去 30 日間)
古いコメントを表示
hi! i am currently trying to get a file out of a folder however, the file names are very similar, differing only at the end by "session1" "session 2" and "session 3"
vdm5_scsEMPT-150406-00001-00001-2_session1
vdm5_scsEMPT-150406-00001-00001-2_session2
vdm5_scsEMPT-150406-00001-00001-2_session3
This is the current code im using to try to get the specific fieldmap, however it gives me all 3 files instead of just 1, which is specific to ses1
fieldmap(subject_number).all = spm_select('FPListRec', [sub_dirs(subject_number,:) '/' direc(indexses1).name],'^vdm5_scs.*.nii');
Anyone know what can i do? Thank you!
2 件のコメント
回答 (1 件)
Jan
2021 年 4 月 8 日
You list of files does not contain the file extension ".nii", but your code does. This looks confusing.
What is the type of sub_dirs? It looks strange, that you access if by: sub_dirs(subject_number,:)
Is it a CHAR matrix? If so: Don't do it, because it is padded with spaces. Create it as srting or cell string instead.
Why do you provide the file as a pattern '^vdm5_scs.*.nii'? If you know, that you want the file 'vdm5_scsEMPT-150406-00001-00001-2_session1.nii', you can specify this directly:
Folder = fullfile(sub_dirs(subject_number,:), direc(indexses1).name);
File = 'vdm5_scsEMPT-150406-00001-00001-2_session1.nii';
fieldmap(subject_number).all = spm_select('FPListRec', Folder , File);
If you have a reason to provide the file as a pattern, use a pattern, which matchs the wanted file only:
Pattern = 'vdm5_scs*_session1.nii';
fieldmap(subject_number).all = spm_select('FPListRec', Folder , Pattern);
参考
カテゴリ
Help Center および File Exchange で Environment and Settings についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!