renaming NII files according to a string of values

조회 수: 2 (최근 30일)
Mariam Kostandyan
Mariam Kostandyan 2018년 2월 8일
댓글: Mariam Kostandyan 2018년 2월 9일
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
Guillaume
Guillaume 2018년 2월 8일
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?
Mariam Kostandyan
Mariam Kostandyan 2018년 2월 9일
The files are retrieved by dir. So, I just set the path to the folder where the files are. The order of the files is defined by their names: beta0001, beta0002, beta0003, beta0004, etc. Importantly, the order of the files corresponds to the order of the values in the string array.

댓글을 달려면 로그인하십시오.

채택된 답변

Walter Roberson
Walter Roberson 2018년 2월 9일
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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 File Operations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by