How to get the exact position of a plotted point?
53 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
BF83
am 17 Aug. 2011
Kommentiert: maziar
am 15 Mai 2021
Hi,
I've plotted a graph and additionally marked a specific point. A 'ButtonDownFcn' is assigned to the point, to enable user interaction.
By clicking onto the point I would like to receive its exact x and y coordinates.
My approach:
function getPlotPointCoord()
clc;
figure(1);
x = -2*pi:0.05:+2*pi;
subplot(1,2,1);
hold on;
plot(x, sin(x));
% plot point at (x=0, y=0)
plot(0, sin(0), 'bx', 'ButtonDownFcn', @getPoint);
function getPoint(varargin)
currentPoint = get(gca, 'CurrentPoint');
fprintf('Hit Point! Coordinates: %f, %f \n', ...
currentPoint(1), currentPoint(3));
end
end
The call _get(gca, 'CurrentPoint') for instance returns the following values:
Hit Point! Coordinates: 0.000000, 0.002924
Hit Point! Coordinates: 0.000000, 0.002924
Hit Point! Coordinates: 0.000000, 0.002924
Hit Point! Coordinates: -0.106952, -0.008772
Hit Point! Coordinates: 0.106952, -0.014620
Is there a way to receive the true values (x=0, y=0) of the 'button' instead of the current (most likely) mouse-coordinates?
Thank you!
0 Kommentare
Akzeptierte Antwort
Fangjun Jiang
am 17 Aug. 2011
What do you mean? You want the x/y value of the data points? You can get that from menu Tools->Data Cursor and then click along the curve.
8 Kommentare
Trishank Sharma
am 8 Jul. 2018
Bearbeitet: Trishank Sharma
am 8 Jul. 2018
Hi what if I have a set of 60 points (n=60), where x and y are real and imaginary parts of a complex number Z. Can I know the point number (the 'n'th point) beside the coordinates or do I have to do it manually?
Weitere Antworten (3)
Tarami Readus
am 23 Jan. 2019
Where in the code does he add the marker, and to what specific point? I would like to know how to do that
0 Kommentare
Adam Albayati
am 8 Mai 2019
function getPlotPointCoord()
clc;
figure(1);
x = -2*pi:0.05:+2*pi;
subplot(1,2,1);
hold on;
plot(x, sin(x));
% plot point at (x=0, y=0)
plot(0, sin(0), 'bx', 'ButtonDownFcn', @getPoint);
function getPoint(varargin)
currentPoint = get(gca, 'CurrentPoint');
fprintf('Hit Point! Coordinates: %f, %f \n', ...
currentPoint(1), currentPoint(3));
end
end
0 Kommentare
Siehe auch
Kategorien
Mehr zu Scatter Plots finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!