renaming NII files according to a string of values
1 vue (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mariam Kostandyan
le 8 Fév 2018
Commenté : Mariam Kostandyan
le 9 Fév 2018
I have a string:
cond = [string('CSRA_Rcon'); string('CSRA_Rinc'); string('CSRA_Ucon')];
and .NII files (betas from the spm fmri: beta0001.nii, beta0002.nii, beta0003.nii) that I want to rename according to the string, so the names would be: CSRA_Rcon.nii, CSRA_Rinc.nii, CSRA_Ucon.nii.
What's the optimal way of doing it?
2 commentaires
Guillaume
le 8 Fév 2018
I would think that
cond = string({'CSRA_Rcon'; 'CSRA_Rinc'; 'CSRA_Ucon'});
would be an easier way to create your string array.
How do you determine that 'beta0001.nii' has to be renamed to 'CSRA_Rcon.nii' ? How are the original names obtained in the first place? Is it another string array that you create or are they retrieved by dir? If the latter what defines the order?
Réponse acceptée
Walter Roberson
le 9 Fév 2018
cond = {'CSRA_Rcon', 'CSRA_Rinc', 'CSRA_Ucon'};
dinfo = dir('beta*.nii');
nfiles = length(dinfo);
if nfiles ~= length(cond)
error('Number of available files does not match number of available names, nothing renamed');
end
for K = 1 : nfiles
movefile(dinfo(K).name, cond{K});
end
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur File Operations dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!