我正在尝试将代码转换为使用parfor运行,因为它需要很长时间才能自行运行。但是我一直收到这个错误。我在网站上搜索并阅读了有类似问题的人,但这些答案似乎都无法解决我的问题。这是我的代码:
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
我正在尝试计算阵列上特定位置的电场,并且matlab给出了错误“parfor中的变量A不能被分类”。我需要帮助。感谢。
答案 0 :(得分:0)
由于不允许对parfor循环中的变量进行分类,因此应尝试将每个循环的输出保存在变量&然后将最终输出保存到所需的变量中, A 在您的情况下! 这应该可以胜任 -
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
通过以下内容以便更好地理解 - http://www.mathworks.com/help/distcomp/classification-of-variables-in-parfor-loops.html http://in.mathworks.com/help/distcomp/sliced-variable.html