Parfor Loop Error with Classification
显示 更早的评论
When trying to convert the outer loop of the code below to a parfor loop, the error is:
Error: The variable z_new in a parfor cannot be classified.
See Parallel for Loops in MATLAB, "Overview"
Following the instruction on another post, I used a temporary variable to represent z_new, but that did not work either. Can anyone see what needs to be changed to permit this to run with parfor?
x = linspace(0,6,100); y = x; [xx,yy] = meshgrid(x,y);
z = sin(xx + 0.25*yy);
dx = 1; dy = 1; Dep = 100*ones(size(z));
z_new = z + Dep;
[nr,nc] = size(z);
nnx = round(Dep/dx,0); nny = round(Dep/dy,0);
parfor i = 1:nc
for j = 1:nr
for ii = i-nnx(j,i):i+nnx(j,i)
for jj = j-nny(j,i):j+nny(j,i)
iinew = ii;
jjnew = jj;
Thk = Dep.*Dep - dx*dx*(i-ii)*(i-ii) - dy*dy*(j-jj)*(j-jj);
if (ii > 0 && ii <= nc && jj > 0 && jj <= nr && Thk(j,i) >= 0)
Th_tmp = z(j,i) + sqrt(Thk(j,i));
if (iinew > 0 && iinew <= nc && jjnew > 0 && jjnew <= nr)
if z_new(jjnew,iinew) < Th_tmp
z_new(jjnew,iinew) = Th_tmp;
end
end
end
end
end
end
end
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Loops and Conditional Statements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!