how to load a variable in a loop

3 views (last 30 days)
Native
Native on 20 Aug 2019
Edited: Stephen23 on 20 Aug 2019
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

Answers (1)

Stephen23
Stephen23 on 20 Aug 2019
Edited: Stephen23 on 20 Aug 2019
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

Categories

Find more on Automotive in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!