MATLAB coding/loop question

8 visualizzazioni (ultimi 30 giorni)
Benjamin Davidson
Benjamin Davidson il 1 Apr 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 Commenti
Stephen23
Stephen23 il 6 Apr 2019
Modificato: Stephen23 il 6 Apr 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 il 8 Apr 2019
Thank you both for your feedback, this is exactly what I needed!
Much appreciated.
Ben

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Startup and Shutdown in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by