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
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
Benjamin Davidson
Thank you both for your feedback, this is exactly what I needed!
Much appreciated.
Ben

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Startup and Shutdown 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by