MATLAB: How to get values of X,Y,Z when i point courser on the graph

datatipgraphplotscopeselect dots

Here is the graph what i have
Capture.PNG
how to get the values of X,Y,Z when i point the courser on the graph?
i need a code which gives me information of all the paramets on the graph at that point

Best Answer

Method 1: use data tips
% Create demo scatter plot
x = linspace(0,3*pi,200);
y = cos(x) + rand(1,200);
sz = 25;
c = linspace(1,10,length(x));
s = scatter(x,y,sz,c,'filled');
% Add an additional row to the data tips showing the color value
datatipRow = dataTipTextRow('C',c);
s.DataTipTemplate.DataTipRows(end+1) = datatipRow;
% Now click on any point to produce the data tip (image below)
Method 2: return value to command window (or anywhere else you'd like)
This uses ginput() which allows the user to click on any space within the axes. It then computes the nearest point and returns its (x,y) coordinate and color value.
% User must select 1 point
[x,y] = ginput(1);
% Get (x,y) coordinates for all points
% *** This assumes the entire point was made with the one
% call to scatter() instead of several calls to scatter().
h = gco();
hx = h.XData;
hy = h.YData;
hc = h.CData;
% Find the nearest point to selection
d = sqrt((x-hx).^2 + (y-hy).^2);
[~,minIdx] = min(d);
% Return the (x,y) and color data
fprintf('(x,y,c) = (%.3f,%.3f,%.3f)\n',hx(minIdx),hy(minIdx),hc(minIdx));