Q:

Error using parfor in matlab // The variable in a parfor cannot be classified

I have the following for loop inside a parfor loop: 
for j1=1:NN
    for j2=1:NN
            HF(j1,j2)=hf(mod((j1-j2),NN)+1);  
     end
end

I get the error message saying:

The variable HF in a parfor cannot be classified.

I do not use or define HF outside the parfor loop or anywhere else. Each iteration creates its own version of HF.
How can I fix this problem?

A:

Because you are not initializing HF outside of the loop, when parsing your code, MATLAB thinks that you are modifying a shared variable HF from within the parfor. This is problematic because multiple workers can't modify the same data. This leads to the error that you are seeing.
To fix this, you need to explicitly pre-allocate HF outside of your loop to help MATLAB figure out that each iteration through the parfor loop is operating on a different HF.
HF = zeros(NN, NN);

for j1=1:NN
    for j2=1:NN
        HF(j1,j2)=hf(mod((j1-j2),NN)+1);  
    end
end

