How to slice a 4-level cell array to perform a parlour
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello Everyone, I was trying to use parfor to speed up my calculations, but without success. I'm using a cell array composed of 4 levels, which is useful for organising my data. However, it seems that if I want to use a cell array in a parfor I should index it "always in the same way" (googled it). To be honest, I can't understand why, in my specific case, the variable I'm using is not sliced, but surely you can do it better than me. I'm attaching some example code to explain my case. I'm sure you guys can help me fixing it. Thanks, Rob
%example
CLASS = 1 : 3;
CASE = 1 : 17;
FYcase = 1 : 9;
FCcase = 1 : 9;
%
for class = CLASS
parfor caso = CASE
for fyCASE = FYcase
for fcCASE = FCcase
ALLcurves{class}{caso}{fyCASE}{fcCASE} = 1; % do something
end
end
end
end
0 Kommentare
Akzeptierte Antwort
OCDER
am 20 Aug. 2018
AllCurves = cell(1, 3);
for class = 1 : 3
C = AllCurves{class};
parfor caso = 1 : 17
A = C{caso};
for fyCASE = 1 : 9
for fcCASE = 1 : 9
A{fyCase}{fcCASE} = 1;
end
end
C{caso} = A; % do something
end
AllCurves{class} = C;
end
To use parfor, one of the requirement must be a 1st-level indexing, as in C{caso} is ok, but C{class}{caso} is not okay (2nd level indexing on the parfor counter variable, caso.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Parallel for-Loops (parfor) finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!