【发布时间】:2013-03-07 11:55:39
【问题描述】:
我有一个包含大约 6000 个项目的散点图。
x = rand(1,6000);
y = rand(1,6000);
scatter(x,y)
有没有办法使用 GUI 找到给定点的索引? (我们放大数据,并希望找到产生某个点的特定索引)
【问题讨论】:
标签: matlab scatter-plot
我有一个包含大约 6000 个项目的散点图。
x = rand(1,6000);
y = rand(1,6000);
scatter(x,y)
有没有办法使用 GUI 找到给定点的索引? (我们放大数据,并希望找到产生某个点的特定索引)
【问题讨论】:
标签: matlab scatter-plot
这是一个非常简单的解决方案:
打开绘图>数据光标>编辑文本更新功能
设置文字更新功能为:
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 = intersect(find(x == cursor_info.Position(1)), find(y == cursor_info.Position(2)));
【讨论】: