首页 > 解决方案 > 使用 Matlab 查找函数使用其坐标获取顶点的索引

问题描述

我有一个包含曲面网格顶点的矩阵 50943x3。我想使用它的坐标 (x,y,z) 找到某个顶点的索引。

我尝试了 Matlab 函数 find 但它返回一个 0×1 的空矩阵。

提前致谢,

干杯

标签: matlabfindmeshsurfacevertex

解决方案


由于浮点舍入错误,您的尝试可能不起作用。你可以在这里阅读更多关于它的信息。您可以查看eps 函数,或者仅使用以下示例:

% Your matrix
M = randn(50943 , 3);

% The coordinates you are looking for
P = [0,0,0];

% Distance between all coordinates and target point
D = sqrt(sum((M - bsxfun(@minus,M,P)).^2,2));

% Closest coordinates to target
[~ , pos] = min(D);

% Display result
disp(M(pos , :))

推荐阅读