How to find the index from a large scatter plot in matlab?
matlab, scatter-plot
Solution
Here's a very simple solution:
Open a plot > data cursor > edit text update function
Set the text update function to:
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
Results:
Just FYI, if you want to do this programatically, then here's a good article on it here.
Problem
I have a scatter plot with about 6000 items. ``` x = rand(1,6000); y = rand(1,6000); scatter(x,y) ``` Is there a way to find the index of a given point using the GUI? (We zoom into data, and want to find the specific index that gave rise to a point)