saving an output with loop
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaire
infinity
le 19 Juil 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)
Réponses (1)
Mario Chiappelli
le 19 Juil 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 :)
0 commentaires
Voir également
Catégories
En savoir plus sur Search Path 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!