saving an output with loop

3 visualizzazioni (ultimi 30 giorni)
Ben
Ben il 19 Lug 2019
Risposto: Mario Chiappelli il 19 Lug 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 Commento
infinity
infinity il 19 Lug 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)

Accedi per commentare.

Risposte (1)

Mario Chiappelli
Mario Chiappelli il 19 Lug 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 :)

Categorie

Scopri di più su Search Path in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by