仅绘制特定长度的线

Only plot lines of specific length

下图显示了等高线图,其中包含已使用质心连接的感兴趣区域。我想要实现的是只绘制一定长度的线。目前,每个点都有一条线连接到其他点。

C=contourf(K{i}); 
[Area,Centroid] = Contour2Area(C);

% This converts any entries that are negative into a positive value
% of the same magnitiude
indices{i} = find( Centroid < 0); 
Centroid(indices{i})=Centroid(indices{i}) * -1; %set all 

% Does the same but for positive (+500)
indices{i} = find( Area > 500); 
Area(indices{i})=0; 

[sortedAreaVal, sortedAreaInd] = sort(Area, 'descend');

maxAreaVals = sortedAreaVal(1:10)';
maxAreaInd = sortedAreaInd(1:10)';

xc=Centroid(1,:); yc=Centroid(2,:);
hold on; plot(xc,yc,'-');

如果有一种方法可以只绘制低于特定阈值的线条,那将非常有用。下一步将是标记和测量每条线。提前感谢您的宝贵时间。

如果 xcyc 是质心的 x 和 y 坐标,那么您可以这样做:

sqrt(sum(diff([x,y],1).^2,2))

这样做是取连续 [x,y] 数据点之间的差异,然后计算它们之间的欧氏距离。然后,您将获得 select 所需的所有信息并标记长度。

有一件事,这只会计算 连续 个质心之间的距离。我这样写是因为看起来这就是你上面想要做的。如果您有兴趣找出 所有 质心之间的距离,则必须遍历并计算距离。 大致如下:

for i=1:length(xc)-1
    for j=i+1:length(xc)
       % distance calculation here...

希望对您有所帮助。