如何在matlab中从大散点图中找到索引?

Joh*_*ohn 4 matlab scatter-plot

我有一个散点图,大约有6000个项目.

x = rand(1,6000);
y = rand(1,6000);
scatter(x,y)
Run Code Online (Sandbox Code Playgroud)

有没有办法使用GUI查找给定点的索引?(我们放大数据,并希望找到产生一个点的具体指数)

Jus*_*tin 6

这是一个非常简单的解决方案:

打开绘图>数据光标>编辑文本更新功能

将文本更新功能设置为:

function output_txt = myFunction(obj,event_obj)
% Display the position of the data cursor
% obj          Currently not used (empty)
% event_obj    Handle to event object
% output_txt   Data cursor text string (string or cell array of strings).

pos = get(event_obj,'Position');

% Import x and y
x = get(get(event_obj,'Target'),'XData');
y = get(get(event_obj,'Target'),'YData');

% Find index
index_x = find(x == pos(1));
index_y = find(y == pos(2));
index = intersect(index_x,index_y);

% Set output text
output_txt = {['X: ',num2str(pos(1),4)], ...
              ['Y: ',num2str(pos(2),4)], ...
              ['Index: ', num2str(index)]};

% If there is a Z-coordinate in the position, display it as well
if length(pos) > 2
    output_txt{end+1} = ['Z: ',num2str(pos(3),4)];
end
Run Code Online (Sandbox Code Playgroud)

结果:

在此输入图像描述

仅供参考,如果你想以编程方式做到这一点,那么这里就可以了很好的文章在这里.