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

62 visualizzazioni (ultimi 30 giorni)
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 Commenti
Adam Danz
Adam Danz il 23 Lug 2019
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
Ruthvik sainath meka il 23 Lug 2019
i tried using pcolor
and gave input for x,y,z values it says the z matrix dimension error

Accedi per commentare.

Risposta accettata

Adam Danz
Adam Danz il 23 Lug 2019
Modificato: Adam Danz il 23 Lug 2019
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 Commenti
Ruthvik sainath meka
Ruthvik sainath meka il 23 Lug 2019
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 il 23 Lug 2019
Modificato: Adam Danz il 25 Lug 2019
"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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Discrete Data Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by