Info
La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.
syntax question-- how to reference a file based on same starting file name?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Hi all, I am writing a batch file for SPM, but this question should be applicable to anyone who is better at MatLab syntax than I am...
I am getting an error that spm_jobman cannot find the file I am referencing:
1.) Earlier in my script, I made a variable "address":
address = ['M:/Flight/02_Nifti/',subjID,'/',timepoint];
I did this because of our file organization. Each person's data is within a unique subjID folder (with unique #'s such as 5000, etc.). Then, within that subjID folder, each person has multiple timepoint folders (01,02,03, etc.)
2.) Later in my script, I want to reference a file that starts with "mean" found the folder 04_VEMP, which is within each person's timepoint folders. For example, for one person with subjID 5000 and timepoint 01, the full path might be: M:/Flight/02_Nifti/5000/01/04_VEMP/mean_johnsmith_taskbased.nii
The tricky part is that each subject's name is a part of the file name under 04_VEMP. I am not able to change the file names, so how can I make a general statement that will allow me to always reference that file that starts with "mean" but has a different ending for each person? When I am cd'd into the folder containing these files, if I do ls mean*.nii or ls mean*, this returns only the mean file I am interested in. However, I am not sure how to do this same type of thing when referencing a file path in MatLab.
I have tried and gotten errors with:
fprintf(fID,['matlabbatch{1}.spm.spatial.coreg.estimate.ref = {''',[address,'/04_VEMP/mean*.nii,1''};'],'\n']);
fprintf(fID,['matlabbatch{1}.spm.spatial.coreg.estimate.ref = {''',[address,'/04_VEMP/','mean*','1''};'],'\n']);
I think the ,1 is something that I need in this case for SPM, but I am not positive.
Thanks!
0 comentarios
Respuestas (1)
Rik
el 5 de Oct. de 2017
Editada: Walter Roberson
el 5 de Oct. de 2017
Matlab helps you a lot with data type conversion, but it doesn't go all the way. You tried to concatenate a numeric value with a string. Matlab has no way of knowing how it should do that conversion, so it tries to simply cast the data to char. This means that a numeric value 32 is converted to a space, 65 to uppercase A, and so on. To do this correctly you can either use num2str, or use sprintf.
address = sprintf('M:/Flight/02_Nifti/%d/%d',subjID,timepoint);
As for your second question: Matlab can only read one file at a time with this method, so you need to search for the file with dir and then use fopen to generate a fID for the file you want to write to.
list_of_files=dir([address,'/04_VEMP/mean*.nii']);
fID=fopen([address,'/04_VEMP/' list_of_files(1).name],'w');
0 comentarios
La pregunta está cerrada.
Ver también
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!