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

55 次查看(过去 30 天)
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
  4 个评论
Adam Danz
Adam Danz 2019-7-23
I agree with Adam that these data would work well with an imaged. What function did you try and what was the error?
Ruthvik sainath meka
i tried using pcolor
and gave input for x,y,z values it says the z matrix dimension error

请先登录,再进行评论。

采纳的回答

Adam Danz
Adam Danz 2019-7-23
编辑:Adam Danz 2019-7-23
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));
  2 个评论
Ruthvik sainath meka
i tried this code but it is only giving the result once
i have to run the code again to get other values (method 2)
can there be any modification such that it will give values when i click and dont have to run again and again
Adam Danz
Adam Danz 2019-7-23
编辑:Adam Danz 2019-7-25
"can there be any modification..."
Yes. One way to do it is by increasing the number in ginput(). For exampe, ginput(10) requires that the user select 10 points before anything happens. The [x,y] output will be vectors of 10. You'll also need to modify the fprintf() command unless you've implemented a different, more useful output.
Another way is to put method #2 in a loop. Let me know if you get stuck.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Discrete Data Plots 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by