selecting file which name only differs at the end
3 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Jan
on 8 Apr 2021
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);
See Also
Categories
Find more on Environment and Settings in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!