Deleting rows of a matrix inside a parfor

조회 수: 2 (최근 30일)
Anastasios
Anastasios 2012년 11월 22일
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".

답변 (2개)

Walter Roberson
Walter Roberson 2012년 11월 22일
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 2012년 11월 22일
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...

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by