selecting file which name only differs at the end

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 个评论

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.
hmm alright i will look into trying that! thank you so much :)

请先登录,再进行评论。

回答(1 个)

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 个评论

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?

请先登录,再进行评论。

类别

在 帮助中心 和 File Exchange 中查找有关 Workspace Variables and MAT Files 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by