matlab - “parfor 中的变量无法分类”MATLAB
问题描述
我正在尝试将我的代码转换为使用 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 无法分类”。我需要帮助。谢谢。
解决方案
由于不允许在 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
推荐阅读
- selenium - 当我登陆网站时,我无法关闭网站上出现的第一个弹出窗口(https://www.seleniumeasy.com/test/)
- sql-server - 如何连接到在 docker 容器中创建的 SQL Server
- javascript - 单选按钮和普通按钮不通信
- javascript - 在 THREE.js 中渲染多个框并存储在 3 维数组中
- directus - Express-session 已弃用 req.secret;提供秘密选项
- facebook - 如何在网站上导入 facebook 朋友,以便他们可以看到彼此的帐户?
- go - 戈朗 | 将指针分配给指针接收器不起作用
- html - 使用过渡时的vue模态丢帧
- javascript - 如何在对象内映射数组
- video - 如何从ffmpeg av_read_frame中的额外数据处理VPS SPS和PPS