use of cell arrays to store matrices... but parfor gives an error
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I've got a loop which creates three matrices, and I want to store these for each iteration. Previously I've been saving them as indexed files, but I've just discovered cell arrays which appear to be ideal for this purpose.
My code looks like this:
mat_array = cell(3,50);
parfor i = 1:50
[A,B,C] = matrixgenerator(~);
mat_array {1,i} = A;
mat_array {2,i} = B;
mat_array {3,i} = C;
end
However, I'm getting an error message that mat_array is "indexed in different way, potentially causing dependencies between iterations". I don't understand this error, and don't see where any conflict could arise. Can anyone help me with a workaround?
Thanks
0 comentarios
Respuesta aceptada
Edric Ellis
el 15 de Mzo. de 2013
Try:
mat_array = cell(3,50);
parfor i = 1:50
[a,b,c] = matrixgenerator(~);
mat_array(:,i) = {a,b,c};
end
In this way, you're performing a single indexing operation into mat_array, in a way that the PARFOR infrastructure can understand (i.e. the subscripts are a combination of the loop variable, and the literal ':').
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!