Luis Lira
Luis Lira

Reputation: 11

"Variable in a parfor cannot be classified" MATLAB

I am trying to convert my code over to run with parfor, since as it is it takes a long time to run on its own. However I keep getting this error. I have search around on the website and have read people with similar problems, but none of those answers seem to fix my problem. This is my code:

r = 5;

Mu = 12.57e-9;

Nu = 12e6;

I = 1.8;

const = pi*Nu*Mu*r*I;

a = 55;

b = 69;

c = 206;

[m,n,p] = size(Lesion_Visible);

A = zeros(m,n,p);

parpool(2)

syms k

parfor J = 1:m
     for  I = 1:n
         for K = 1:p
             if Lesion_Visible(J,I,K) ~= 0
                  Theta = atand((J-b)/(I-a));
                  Rho = abs((I-a)/cosd(Theta))*0.05;
                  Z = abs(c-K)*0.05;
                  E = vpa(const*int(abs(besselj(0,Rho*k)*exp(-Z*k)*besselj(0,r*k)),0,20),5);
                  A (J,I,K) = E;
             end
         end
    end
end

I'm trying to calculate the electric field in specific position on an array and matlab give me the error "The variable A in a parfor cannot be classified". I need help. Thanks.

Upvotes: 0

Views: 2244

Answers (1)

Rahul
Rahul

Reputation: 171

As classification of variables in parfor loop is not permitted, you should try to save the output of each loop in a variable & then save the final output into the desired variable, A in your case! This should do the job-

parfor J = 1:m

B=zeros(n,p); %create a padding matrix of two dimension 
for  I = 1:n
    C=zeros(p); %create a padding matrix of one dimension
       for K = 1:p
         if Lesion_Visible(J,I,K) ~= 0
              Theta = atand((J-b)./(I-a));
              Rho = abs((I-a)./cosd(Theta))*0.05;
              Z = abs(c-K).*0.05;
              E = vpa(const.*int(abs(besselj(0,Rho.*k).*exp(-Z.*k).*besselj(0,r.*k)),0,20),5);
              C(K) = E; %save output of innnermost loop to the padded matrix C
         end
       end
     B(I,:)=C; % save the output to dim1 I of matrix B


end
A(J,:,:)=B; save the output to dim1 J of final matrix A
end

Go through the following for better understanding- http://www.mathworks.com/help/distcomp/classification-of-variables-in-parfor-loops.html http://in.mathworks.com/help/distcomp/sliced-variable.html

Upvotes: 1

Related Questions