In MATLAB, I can select a data point using the Data Cursor tool and it will display the X and Y of that point ( see figure below ).
Is it possible to wait for the user to click a point then store the X coordinate (or index) of this point to a variable within my code? It doesn't necessarily have to be using the Data Cursor tool, I just need a way to store the clicked point.
I was able to solve this using the function datacursormode
documented through MathWorks here: I should have done some deeper digging.
Here is what I did:
dcmObject = datacursormode;
pause
datacursormode off
cursor = getCursorInfo(dcmObject);
x = cursor.Position(1)
The code turns on Data Cursor, waits for the user to select a point and then stores the position of the cursor.
You can get the coordinates from a rendered image or plot via:
msgbox('Click on the plot')
[x y] = ginput(1)
%%%%%%%%%%%%%%
x is the x coordinate of the click
y is the y coordinate of the click
References
<http://www.mathworks.com/help/matlab/ref/ginput.html>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.