Deleting rows of a matrix inside a parfor

3 visualizaciones (últimos 30 días)
Anastasios
Anastasios el 22 de Nov. de 2012
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".

Respuestas (2)

Walter Roberson
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.

Anastasios
Anastasios el 22 de Nov. de 2012
Hi Walter,
Thanks a lot for your reply.
Well basic the case is that I have a cell of arrays and I am deleting a line of an array, so I am not actually changing the size of the container cell.
In any case, I just created a function that is called inside the parfor to do this task and it works...

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!

Translated by