Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/matlab/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用cellfun在Matlab中加速while循环_Matlab_While Loop - Fatal编程技术网

使用cellfun在Matlab中加速while循环

使用cellfun在Matlab中加速while循环,matlab,while-loop,Matlab,While Loop,我在Matlab中有以下代码 pc = [0.0195 0.2356 0.6280 0.0229 0.2356 0.6280 0.0393 0.2318 0.6180 0.0196 0.2350 0.6310 0.0212 0.2343 0.6290 0.0230 0.2350 0.6310 0.0245 0.2332 0.6260 0.0378 0.

我在Matlab中有以下代码

pc = [0.0195    0.2356    0.6280
    0.0229    0.2356    0.6280
    0.0393    0.2318    0.6180
    0.0196    0.2350    0.6310
    0.0212    0.2343    0.6290
    0.0230    0.2350    0.6310
    0.0245    0.2332    0.6260
    0.0378    0.2313    0.6210
    0.0408    0.2294    0.6160
    0.0426    0.2302    0.6180];

x = pc(:,1);
y = pc(:,2);
z = pc(:,3);

dt = delaunayTriangulation(pc);
dtTri = [dt(:,[1,2,3]);dt(:,[2,3,4]);dt(:,[1,2,4]);dt(:,[1,3,4])];
dtTri = unique(sort(dtTri,2),'rows');

i = 1;
lim = .005;

while (i<=size(dtTri,1))
    d12 = sqrt(abs(x(dtTri(i,1))-x(dtTri(i,2)))^2+...
        abs(y(dtTri(i,1))-y(dtTri(i,2)))^2+...
        abs(z(dtTri(i,1))-z(dtTri(i,2)))^2);

    if (d12>lim)
        dtTri(i,:)=[];
        continue;
    end
    i = i+1;
end
pc=[0.0195 0.2356 0.6280
0.0229    0.2356    0.6280
0.0393    0.2318    0.6180
0.0196    0.2350    0.6310
0.0212    0.2343    0.6290
0.0230    0.2350    0.6310
0.0245    0.2332    0.6260
0.0378    0.2313    0.6210
0.0408    0.2294    0.6160
0.0426    0.2302    0.6180];
x=pc(:,1);
y=pc(:,2);
z=pc(:,3);
dt=Delaunay三角剖分(pc);
dtTri=[dt(:,[1,2,3]);dt(:,[2,3,4]);dt(:,[1,2,4]);dt(:,[1,3,4]);
dtTri=unique(排序(dtTri,2),‘行’);
i=1;
lim=.005;
while(ilim)
dtTri(i,:)=[];
继续;
结束
i=i+1;
结束

在Matlab中是否有任何方法可以减少上述代码(
while
loop)的运行时间,使用类似于
cellfun
?因为我的
pc
大小非常大,运行代码需要很长时间。谢谢。

如果我了解问题所在,您可以在期间删除整个
,并用以下代码替换它:

 d12 = sqrt((x(dtTri(:,1))-x(dtTri(:,2))).^2 + ...
 (y(dtTri(:,1))-y(dtTri(:,2))).^2 + ...
 (z(dtTri(:,1))-z(dtTri(:,2))).^2);
 foundLimit = find(d12 <= lim);
 newDtTri = dtTri(foundLimit,:);
d12=sqrt((x(dtTri(:,1))-x(dtTri(:,2))。^2+。。。
(y(dtTri(:,1))-y(dtTri(:,2))。^2+。。。
(z(dtTri(:,1))-z(dtTri(:,2))。^2);

foundLimit=find(d12)很好用。非常感谢。刚刚更改了'foundLimit=find(d12