从Matlab图中检索X和Y值 [英] Retrieving X and Y values from Matlab Plot

查看:941
本文介绍了从Matlab图中检索X和Y值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绘图,我想用鼠标从绘图中选择特定的数据点时检索x和y坐标.

I have a plot figure and I want to retreive x and y cordinates when we select particular data point using mouse from plot figure.

有什么想法吗?

推荐答案

另一种选择是使用按钮按下功能:

Another option is to use the button down function:

function mouseExample()
    h = plot(rand(10,1), 'o-');
    set(h, 'ButtonDownFcn',@buttonDownCallback)

    function buttonDownCallback(o,e)
        p = get(gca,'CurrentPoint');
        p = p(1,1:2);
        title( sprintf('(%g,%g)',p) )
    end
end

请注意,这不仅适用于数据点",而且适用于单击行的位置的内插(x,y)位置.您可以通过搜索最接近的实际点来处理结果,并测试点击是否在可接受的半径范围内.

Note this will not only work on "data-points", but rather on interpolated (x,y) positions of where you clicked on the lines. You could process the result by searching for the nearest actual point, and test if the click was within a reasonable radius to accept it.

显然,像其他人指出的那样,仅使用数据游标模式要容易得多...

Obviously it is a lot easier to just use the data cursor mode as other have noted...

这篇关于从Matlab图中检索X和Y值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆