saving an output with loop
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
infinity
2019-7-19
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)
回答(1 个)
Mario Chiappelli
2019-7-19
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Search Path 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!