Deleting rows of a matrix inside a parfor
    4 visualizzazioni (ultimi 30 giorni)
  
       Mostra commenti meno recenti
    
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 Commenti
Risposte (2)
  Walter Roberson
      
      
 il 22 Nov 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 Commenti
Vedere anche
Categorie
				Scopri di più su Loops and Conditional Statements in Help Center e File Exchange
			
	Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

