2

如何在单击时找到点的索引并将其添加到数组、列表或向量的末尾?

h=figure;
image(result);
locx = [];
locy = [];
while (ishandle(h))
    pos = get(0, 'PointerLocation');
    locx(end + 1) = pos(1);
    locy(end + 1) = pos(2);
    pause(1);
end

虽然我只单击了两个点来查看它们的 x、y 和索引,但许多 x 位置已保存在 locx 数组中。请提出解决方案和修复:

locx =

  Columns 1 through 16

         635        1116         231         758         771         591         596          46         116         116         116        1362         852         498        1920        1663

  Columns 17 through 32

         733         795         795        1920        1895        1806        1061         700         123        1102        1097        1615           1         226         233         233

  Columns 33 through 43

         191         854         836        1920        1920        1920        1920        1920        1905        1189        1912

在此处输入图像描述

在此处输入图像描述

4

1 回答 1

3

我建议改用该ginput功能:

h = figure;
image(result);
[locx, locy] = ginput(2);

这将为您提供轴内的点,必须通过四舍五入将其转换为图像的索引:

locx = round(locx);
locy = round(locy);
于 2017-02-20T20:58:36.457 回答