How to slice a 4-level cell array to perform a parlour
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
采纳的回答
OCDER
2018-8-20
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.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Parallel for-Loops (parfor) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!