我有一个散点图,大约有6000个数据点。
x = rand(1,6000);
y = rand(1,6000);
scatter(x,y)
是否有一种方法可以使用GUI找到给定点的索引?(我们将数据放大,想要找到产生该点的特定索引)
我有一个散点图,大约有6000个数据点。
x = rand(1,6000);
y = rand(1,6000);
scatter(x,y)
是否有一种方法可以使用GUI找到给定点的索引?(我们将数据放大,想要找到产生该点的特定索引)
这里有一个非常简单的解决方案:
打开绘图 > 数据光标 > 编辑文本更新函数
将文本更新函数设置为:
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
结果:
顺便说一下,如果您想以编程方式完成此操作,那么这里有一篇很好的文章here。
您可以使用X、Y位置来搜索该点:
%export the cursor to the workspace
possibleXpositions = find(x == cursor_info.Position(1));
possibleYPositions = find(y == cursor_info.Position(2));
position = intersect(possibleXpositions, possibleYPositions);
position将保存您选择的随机数的索引。
作为一行代码:
position = intersect(find(x == cursor_info.Position(1)), find(y == cursor_info.Position(2)));