How to slice a 4-level cell array to perform a parlour
1 view (last 30 days)
Show older comments
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 Comments
Accepted Answer
OCDER
on 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.
More Answers (0)
See Also
Categories
Find more on Parallel for-Loops (parfor) 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!