I am new to use parfor, I have searched for the condition but I still can't understand what to do in order to make it work.

1 view (last 30 days)
I have a code like this...
Copt = cell(65,65);
parfor ws = 1:size(wsv,1)
t=wsv(ws,1);
u=wsv(ws,2);
...
...
Copt{t,u} = -2;
...
...
...
C = corr2(F1,F2);
if (C > Copt{t,u}) %C returns correlation coef.%
Copt{t,u} = C;
end
end
"Error: The variable in a parfor cannot be classified." displays on the command window when I run my code.
I don't know what to do, is there anyone can give me suggestion?

Accepted Answer

Edric Ellis
Edric Ellis on 3 Apr 2014
To run a PARFOR loop, all variables that you wish to produce as results from the loop must either be sliced or reductions. A sliced variable is one where each iteration of the loop fills out a "slice" which is a subset of the array based on the loop variable. In your case, because you are not indexing "Copt" with the loop index "ws", it cannot be sliced, and so MATLAB cannot work out if your loop is safe to run in parallel.
There's more about variable types in PARFOR here: http://www.mathworks.co.uk/help/distcomp/advanced-topics.html#bq_of7_-1
  1 Comment
Wing Tim Man
Wing Tim Man on 3 Apr 2014
Thanks a lot. I make another cell to contain the value first, say , Copta{wv} = C; so that it can be sliced. After the parfor loop, I use another for loop to write the value back,i.e. for i = 1:size(wsv,1) Copt{wsv(i,1),wsv(i,2)} = Copta{i}; end
And it works !

Sign in to comment.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!