matlab - 简化Matlab中meshgrid的使用

标签 matlab image-processing geometry

背景

扩展this问题。我有一个点的集合(在三轴系统中,因此具有 (x,y,z) 坐标),并且我想计算每个点之间的距离。

为此,我首先必须创建一个包含所有可能的点组合的矩阵(最好没有重复项,以节省处理时间),然后计算所有距离。

问题

现在我尝试使用meshgrid来实现此目的,但它变得非常复杂。它变得很复杂,因为 (x,y,z) 坐标位于格式为以下的矩阵中:pointCooperatives[x,y,z,pointnumber]

而且我不知道如何告诉 meshgrid 仅组合 point-1 和 point-2 等,而不将所有单独的 x 坐标与所有单独的 y 坐标组合,等等(组合太多了,其中大多数都是无用的)。

问题

如何防止网格网格产生冗余的坐标组合?或者有更简单的方法吗?


我想我可以将点坐标矩阵重新格式化为简单的字符串数组点(具有与坐标一样多的条目)。其中条目一是 (1,3,5),条目二是 (2,4,2),等等。从而将坐标保持在一起,并限制可能组合的数量。但这似乎是多余的。

最佳答案

确实有更简单的方法。如果只想计算非冗余点,可以使用pdist 。请注意,您可以选择与欧几里德距离度量不同的距离度量。

distances = pdist(pointCoordinates(:,1:3));

来自帮助:

The output D is arranged in the order of ((2,1),(3,1),..., (m,1),(3,2),...(m,2),.....(m,m–1)), i.e. the lower left triangle of the full m-by-m distance matrix in column order. To get the distance between the ith and jth observations (i < j), either use the formula D((i–1)*(m–i/2)+j–i), or use the helper function Z = squareform(D), which returns an m-by-m square symmetric matrix, with the (i,j) entry equal to distance between observation i and observation j.

关于matlab - 简化Matlab中meshgrid的使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9483363/

相关文章:

python - 使用 openCV 检测墙角 - 硬

image-processing - 实时跟踪多个简单物体的算法

c++ - 如何从位置和地标获取 (X,Y) vector

c++ - 如何将 MATLAB Lab 色标转换为 OpenCV Lab 色标?

python - 相当于 MATLAB 元胞数组的 Numpy

user-interface - 如何将进度条控件添加到 Matlab gui?

matlab - 在 Matlab 中创建相关图

Python Image.open() 给出 'object has no attribute' 错误

reactjs - React-Leaflet 在 map 上绘制圆形标记

android - 需要圆形裁剪功能而不是矩形