根据距离着色点

时间:2014-12-16 13:59:11

标签: matlab matlab-figure

我有一组坐标,我想计算这些点之间的距离,并根据一个特定的值,比如说1.3。我想用蓝色点颜色:

我开始这样的程序:

M=load('data.csv');
xA=M(1:514,1);
yA=M(1:514,2);
xB=M(514:1027,1);
yB=M(514:1027,2);
PosA =[xA yA];
[num1] = size(PosA); 
R = zeros(num1,num1);

 for i=1:num1
    for j=1:num1
        for k=1:num1
            for l=1:num1
                if i~=j~=k~=l
                R(i,j)=norm(PosA(i,:)-PosA(j,:));
                R(j,k)=norm(PosA(j,:)-PosA(k,:));
                R(k,l)=norm(PosA(k,:)-PosA(l,:));
                R(l,i)=norm(PosA(l,:)-PosA(i,:));
                if(R(i,j)=1.3284 & R(j,k)=1.44 & R(k,l)=1.33 &R(l,i)=1.32)
                    plot(xA(i),yA(i),'bo') /*and here is my problem exactly I'm not sure about how to give the correct indexing so that if I calculated the distances between these points and it satisfy the condition to plot these points in blue*/

                else
                    plot(xA,yA,'ro') /*else plot the points in red*/

                end
            end
        end
    end
end

2 个答案:

答案 0 :(得分:1)

使用逻辑索引查找d<1.3的所有点并分别绘制这些点。

plot(x(d<1.3),y(d<1.3),'b.',x(d>=1.3),y(d>=1.3,'r.');

答案 1 :(得分:0)

您将需要使用bwdist命令。假设您为您的兴趣点选择了第2,2点:

编辑为蓝色:

bw = zeros(5,5);  %  Define a 5x5 matrix of zeros
bw(2,2) = 1;      %  Set your coordinate to the value 1

D = bwdist(bw);   %  For all pixels, calculates the distance from your point

mask = (D < 1.3);  % Create a mask of points with distance below your threshold

bwout = bw;
bwout(:,:,3) = mask;  
image(bwout);      %  Creates an image where points below your threshold are blue