Matlab代码应停止重复,但仍会重复

时间:2019-06-28 18:03:22

标签: matlab

我正在尝试编写一个程序,通过查找原始点周围的点是否在原始点的边界内来找到图形的轮廓。我试图写一个小节,以防止点查看轮廓中已包含的点(使用变量a,b,c,d)。我当前的代码是

while 1
    [m M] = size(already_boxed);
    x=0;

    for n = 1:m
        a=0;
        b=0;
        c=0;
        d=0;
        for w = 1:m
            if already_boxed(w,:) == [(already_boxed(n,1)+1), already_boxed(n,2)]
                a=1;
            end
            if already_boxed(w,:) == [(already_boxed(n,1)-1), already_boxed(n,2)]
                b=1;
            end
            if already_boxed(w,:) == [already_boxed(n,1), (already_boxed(n,2)+1)]
                c=1;
            end
            if already_boxed(w,:) == [already_boxed(n,1), (already_boxed(n,2)-1)]
                d=1;
            end
        end
        if a==0
            if subimages((already_boxed(n,1)+1), already_boxed(n,2))<subimages(already_boxed(n,1),already_boxed(n,2))*0.9 && subimages((already_boxed(n,1)+1), already_boxed(n,2))>subimages(already_boxed(n,1),already_boxed(n,2))*1.1 
                already_boxed = [already_boxed; (already_boxed(n,1)+1), already_boxed(n,2)];
                x=1;
            end
        end
        if b ==0
            if subimages((already_boxed(n,1)-1), already_boxed(n,2))<subimages(already_boxed(n,1),already_boxed(n,2))*0.9 && subimages((already_boxed(n,1)-1), already_boxed(n,2))>subimages(already_boxed(n,1),already_boxed(n,2))*1.1 
                already_boxed = [already_boxed; (already_boxed(n,1)-1), already_boxed(n,2)];
                x=1;
            end
        end
        if c==0
            if subimages(already_boxed(n,1), (already_boxed(n,2)+1))<subimages(already_boxed(n,1),already_boxed(n,2))*0.9 && subimages(already_boxed(n,1), (already_boxed(n,2)+1))>subimages(already_boxed(n,1),already_boxed(n,2))*1.1 
                already_boxed = [already_boxed; already_boxed(n,1), (already_boxed(n,2)+1)];
                x=1;
            end
        end
        if d ==0
            if subimages(already_boxed(n,1), (already_boxed(n,2)-1))<subimages(already_boxed(n,1),already_boxed(n,2))*0.9 && subimages(already_boxed(n,1), (already_boxed(n,2)-1))>subimages(already_boxed(n,1),already_boxed(n,2))*1.1 
                already_boxed = [already_boxed; already_boxed(n,1), (already_boxed(n,2)-1)];
                x=1;
            end
        end
    end

    if x == 0
        break
    end
end

现在,该代码将一直持续下去,因为它一直在检查在线的点。例如,变量“ already_boxed”将包含双打:

119,288
120,288
118,288
119,289
119,287
119,288

我不知道为什么119,288出现两次,而我只希望它出现一次。我该如何解决?

0 个答案:

没有答案