MATLAB Answers

Native
0

how to load a variable in a loop

Asked by Native
on 20 Aug 2019 at 5:19
Latest activity Edited by Stephen Cobeldick on 20 Aug 2019 at 5:56
ROI_epi.mat contains the variable ROI, which I need to load within the loop. How can I do this?
D = dir('CC*/Rest/ROI_epi.mat')
for i = 1:length(D)
a = struct2cell(ROI);
y = a(9,:,:);
%Salience%
ACGl = y{31};
ACGr = y{32};
Insl = y{29};
Insr = y{30};
%DMN%
MOFl = y{25};
MOFr = y{26};
PCCl = y{35};
PCCr = y{36};
IPCl = y{61};
IPCr = y{62};
%CEN%
MFGl = y{7};
MFGr = y{8};
SPCl = y{59};
SPCr = y{60};
%Thal%
lThal = y{77};
rThal = y{78};
TS = horzcat(ACGl,ACGr,Insl,Insr,MOFl,MOFr,PCCl,PCCr,IPCl,IPCr,MFGl,MFGr,SPCl,SPCr,lThal,rThal);
TSd = detrend(TS);
save(['TSd_' num2str(i)])
end

  0 Comments

Sign in to comment.

1 Answer

Answer by Stephen Cobeldick on 20 Aug 2019 at 5:55
Edited by Stephen Cobeldick on 20 Aug 2019 at 5:56

D = dir('CC*/Rest/ROI_epi.mat');
for k = 1:numel(D)
F = fullfile(D(k).folder,D(k).name);
S = load(F);
ROI = S.ROI;
...
end

  0 Comments

Sign in to comment.