selecting file which name only differs at the end

6 ビュー (過去 30 日間)
Ashley Lee
Ashley Lee 2021 年 4 月 8 日
編集済み: Stephen23 2021 年 4 月 9 日
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 件のコメント
Stephen23
Stephen23 2021 年 4 月 8 日
編集済み: Stephen23 2021 年 4 月 9 日
I guess that your OS is set to hide file extensions of known filetypes. I recommend changing this setting, so that you can see the file extensions.
Ashley Lee
Ashley Lee 2021 年 4 月 9 日
hmm alright i will look into trying that! thank you so much :)

サインインしてコメントする。

回答 (1 件)

Jan
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);
  1 件のコメント
Ashley Lee
Ashley Lee 2021 年 4 月 9 日
Hi there! Thank you for all your feedback and suggestions :)
im sorry, but the files actually do contain .nii, that's my mistake, it actually looks like:
vdm5_scsEMPT-150406-00001-00001-2_session1.nii
And yes, it is a char matrix.
I have tried out your above code, with the pattern (as i am trying to create a loop), but it doesnt seem to be giving me any output.
Would you perhaps have any idea why?

サインインしてコメントする。

カテゴリ

Help Center および File ExchangeEnvironment and Settings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by