【问题标题】:"Variable in a parfor cannot be classified" MATLAB“parfor 中的变量无法分类”MATLAB
【发布时间】:2018-10-24 17:40:30
【问题描述】:

我正在尝试将我的代码转换为使用 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 无法分类”。我需要帮助。谢谢。

【问题讨论】:

    标签: matlab for-loop parallel-processing classification parfor


    【解决方案1】:

    由于不允许在 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-19
      • 2015-05-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多