필터 지우기
필터 지우기

How to slice a 4-level cell array to perform a parlour

조회 수: 1 (최근 30일)
rob
rob 2018년 8월 20일
댓글: rob 2018년 8월 21일
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

채택된 답변

OCDER
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.
  댓글 수: 1
rob
rob 2018년 8월 21일
great. Your explanation is super easy! Thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Parallel for-Loops (parfor)에 대해 자세히 알아보기

태그

제품


릴리스

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by