MATLAB coding/loop question
8 次查看(过去 30 天)
显示 更早的评论
Hi there, I have a coding quesion! I'm writing a scrip for neuroimaging analysis. Some subjects have 1 functional scan, some have 2, it's about 50-50 and there's no way to predict. Is there any easy way to allow my code to be flexible for this? My code is below
for i = 1:2
for j = 1:2
filename = sprintf('/media/nir/SharedDrive/Ben/BATCHtester1/Sub014%d_Ses1/Sub014%d_Ses1_Scan_0%d_BOLD%d.nii', i, i, j + 1, j)
BATCH.Setup.functionals{i}{j}= filename;
clear filename;
end
end
Thank you!
8 个评论
Stephen23
2019-4-6
编辑:Stephen23
2019-4-6
Simplify the code by defining the root path before the loop:
N = 1400;
R = '/media/nir/SharedDrive/Ben/BATCHtester1';
for ii = 1:N
D = sprintf('Sub014%d_Ses1', ii);
S = dir(fullfile(R,D,'*.nii'));
for jj = 1:numel(S)
F = fullfile(R,D,S(jj).name);
... your code
end
end
回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!