Deleting rows of a matrix inside a parfor
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hello,
I am trying to modify the rows of an array inside a parfor. A toy example is like this:
////////////////////////
test = cell(1,1)
test{1} = magic(5)
parfor i =1
test{i}(1,:) =1;
end
//////////////////
And this works fine.
But when I try this one:
/////////////////////////
parfor i =1
test{i}(1,:) = [];
end
///////////////////
I get this:
??? Error: The variable test in a parfor cannot be classified. See Parallel for Loops in MATLAB, "Overview".
0 comentarios
Respuestas (2)
Walter Roberson
el 22 de Nov. de 2012
It is not legal to change the size of an indexed array within the parfor.
In your example you are only looping once, but if you were looping more than once, then when i=2, what would test{i} refer to? Would it refer to the second element of the array as it was when the loop was entered, or would it refer to the second element of the array after the first element was deleted (that is, what was originally the third element of the array) ? The result would depend upon the order the iterations were done in, which is not allowed with parfor: the work you do within parfor() must be independent of the order the iterations are performed.
0 comentarios
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!