saving an output with loop

2 Ansichten (letzte 30 Tage)
Ben
Ben am 19 Jul. 2019
Beantwortet: Mario Chiappelli am 19 Jul. 2019
I have three subject-specific subdirectories (sub-CC121428, ...) in a main directory, 'diffusion'. I have written a `for` loop to convert a .nii file in each subdirectory to a .mat file:
practice_dir = 'C:\Work\FSL\shared\NCCN_project\diffusion'; %
subjects = [121428 420433 710429]; %
for n=1:length(subjects)
i = subjects(n);
subname = sprintf('sub-CC%06d',i);
fname_eddy = fullfile(practice_dir,subname,'dwi',sprintf('eddy_output.nii',subname));
fname_mask = fullfile(practice_dir,subname,'dwi',sprintf('b0_0.3_mask.nii',subname));
CreateROI(fname_eddy, fname_mask, 'NODDI_roi.mat')
end
The output is saved in the first subject subdirectory and is overwritten with each iteration. How do I save the output of each iteration (NODDI_roi.mat) in the correct subject subdirectory?
  1 Kommentar
infinity
infinity am 19 Jul. 2019
Hello,
Did you try to put the path before "NODDI_roi.mat" like
your_sub_direct_file = fullfile(practice_dir,subname,'dwi','NODDI_roi.mat');
Then, you just save your data to this path like
CreateROI(fname_eddy, fname_mask, your_sub_direct_file)

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Mario Chiappelli
Mario Chiappelli am 19 Jul. 2019
Save the ouput in an array based off of what iteration you are on. Something like this:
outputArray = string(length(subjects)); % I assume your output is a string
for n = 1:length(subjects)
% your code
outputArray(n) = CreateROI(fname_eddy, fname_mask, 'NODDI_roi.mat');
end
Hope this helps :)

Kategorien

Mehr zu Search Path finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by