使用容差为散点数据分组
本示例展示如何根据散点数据点与相关点的邻近度对其进行分组。
创建一个随机二维点集。然后创建并在随机数据的上方绘制等间距点网格。
x = rand(10000,2); [a,b] = meshgrid(0:0.1:1); gridPoints = [a(:), b(:)]; plot(x(:,1), x(:,2), '.') hold on plot(gridPoints(:,1), gridPoints(:,2), 'xr', 'Markersize', 6)

使用 ismembertol,在 x 内查找处于 gridPoints 中的网格点容差范围内的数据点。将以下选项与 ismembertol 配合使用:
将
ByRows指定为true,因为点坐标在x的行中。将
OutputAllIndices指定为true,以返回x中处于gridPoints对应行容差范围内的行的所有索引。
[LIA,LocB] = ismembertol(gridPoints, x, 0.05, ... 'ByRows', true, 'OutputAllIndices', true);
针对每个网格点,标绘 x 中处于该网格点容差范围内的点。
figure hold on for k = 1:length(LocB) plot(x(LocB{k},1), x(LocB{k},2), '.') end plot(gridPoints(:,1), gridPoints(:,2), 'xr', 'Markersize', 6)
