Borrar filtros
Borrar filtros

selecting file which name only differs at the end

3 visualizaciones (últimos 30 días)
Ashley Lee
Ashley Lee el 8 de Abr. de 2021
Editada: Stephen23 el 9 de Abr. de 2021
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 comentarios
Stephen23
Stephen23 el 8 de Abr. de 2021
Editada: Stephen23 el 9 de Abr. de 2021
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 el 9 de Abr. de 2021
hmm alright i will look into trying that! thank you so much :)

Iniciar sesión para comentar.

Respuestas (1)

Jan
Jan el 8 de Abr. de 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);
  1 comentario
Ashley Lee
Ashley Lee el 9 de Abr. de 2021
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?

Iniciar sesión para comentar.

Categorías

Más información sobre Environment and Settings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by