我有这个图
[完整分辨率]
我需要在用户输入和显示的 x 轴上的点处制作一条垂直直线该垂直线与我的绘图的交点坐标。
在 MATLAB 中如何做到这一点?
例如:用户输入 1020,然后将在 1020 处绘制一条垂直直线,该直线与绘图的某个点相交,并且将以某种方式显示该点的坐标。
I have this plot
[Full Resolution]
I need to make a straight vertical line at a point on x axis that the user enters and show the coordinates of the intersection of that vertical line with my plot.
How can this be done in MATLAB?
for example: the user enters 1020 then a straight vertical line will be drawn at 1020 that meets the plot at some point and the coordinates of that point will be shown somehow.
发布评论
评论(3)
一种方法是使用 GINPUT 函数使用鼠标以图形方式选择一个点。假设您绘制的数据存储在变量
data
中,以下代码应该执行您想要的操作。上面假设图表的 x 值只是您正在绘制的数据数组的索引,从上面显示的图表来看,情况似乎就是这样。
One way to do this is to use the GINPUT function to graphically select a point using the mouse. Assuming the data you plotted is stored in a variable
data
, the following code should do the sort of thing you want.The above assumes that the x-values of the graph are just indices into the array of data you're plotting, which appears to be the case from the graph you show above.
尝试如下操作:
代码未经测试,并假设您的图形是当前图形,绘制的数据存储在数组“data”中,并且原始绘图是在没有指定额外的 x 向量的情况下完成的。
Try something like:
The code is not tested and assumes that your figure is the current one, the plotted data is stored in the array "data" and that the original plot was done without specifying an extra x-vector.
您还可以使用函数
hline
和vline,
,可从以下位置下载:http://www.mathworks.com/matlabcentral/fileexchange/1039-hline-and-vline它们实际上为您做同样的事情。
you can also use the functions
hline
andvline,
which can be downloaded from: http://www.mathworks.com/matlabcentral/fileexchange/1039-hline-and-vlineThey do practically the same for you.