MATLAB coding/loop question

8 visualizaciones (últimos 30 días)
Benjamin Davidson
Benjamin Davidson el 1 de Abr. de 2019
Comentada: Benjamin Davidson el 8 de Abr. de 2019
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 comentarios
Stephen23
Stephen23 el 6 de Abr. de 2019
Editada: Stephen23 el 6 de Abr. de 2019
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
Benjamin Davidson el 8 de Abr. de 2019
Thank you both for your feedback, this is exactly what I needed!
Much appreciated.
Ben

Iniciar sesión para comentar.

Respuestas (0)

Categorías

Más información sobre Startup and Shutdown en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by