简体   繁体   English

存储图形窗口中单击的数据点的坐标

[英]Store coordinates of a clicked data point from the figure window

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 ). 在MATLAB中,我可以使用Data Cursor工具选择一个数据点,它将显示该点的X和Y( 见下图 )。

在此输入图像描述

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? 是否可以等待用户单击一个点然后将此点的X坐标(或索引)存储到我的代码中的变量? 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. 我能够使用MathWorks中记录的函数datacursormode来解决这个问题:我应该做一些更深入的挖掘。

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. 代码打开Data 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 参考


  1. Graphical input from mouse or cursor , Accessed 2014-07-08, <http://www.mathworks.com/help/matlab/ref/ginput.html> 来自鼠标或光标的图形输入 ,访问2014-07-08, <http://www.mathworks.com/help/matlab/ref/ginput.html>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM