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

1 visualización (últimos 30 días)
rob
rob el 20 de Ag. de 2018
Comentada: rob el 21 de Ag. de 2018
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

Respuesta aceptada

OCDER
OCDER el 20 de Ag. de 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.

Más respuestas (0)

Categorías

Más información sobre Parallel for-Loops (parfor) en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by