【问题标题】:In a MATLAB GUI, extract coordinates by clicking inside a plot and display it在 MATLAB GUI 中,通过在绘图内单击来提取坐标并显示它
【发布时间】:2014-04-21 19:28:39
【问题描述】:

我是 MATLAB 的新手,我到处寻找解决这个问题的方法:

让我们以这个 GUI 为例:

如何通过单击绘图内的某个位置,在文本框中显示x 坐标?

这是我在 GUI 代码中尝试过的代码,但无法让它工作:

function axes1_ButtonDownFcn(hObject, eventdata, handles)

[x y] = get(gca,'CurrentPoint');

set(handles.edit1,'string', num2str(x));

guidata(hObject, handles);

【问题讨论】:

标签: matlab user-interface coordinates extract matlab-guide


【解决方案1】:

编辑:哦,误读了这个问题。我把我原来的答案推到了帖子的底部。它可能仍然有用。给你:

function axes1_ButtonDownFcn(hObject, eventdata, handles)

[x y] = eventdata;

set(handles.edit1,'string', num2str(x));

guidata(hObject, handles);

注意,我见过 eventdata 不起作用的实例。如果您尝试使用它并且它是空的,那么请告诉我,我将尝试使用自定义 datacursormode 工具提示回调函数来引导您完成它,这要复杂得多,但可行。

原文:

datacursormode on

有关更多信息,请参阅this 页面。我在自定义数据光标模式功能和点击绘图方面做了很多工作,所以如果您有更具体的问题,请随时提问。

【讨论】:

    猜你喜欢
    • 2012-11-26
    • 1970-01-01
    • 2017-07-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多