【问题标题】:MATLAB- updating an edit text with the mouseMATLAB-用鼠标更新编辑文本
【发布时间】:2013-10-01 01:23:34
【问题描述】:

我使用 GUIDE 构建了一个 GUI,它非常简单,它有两个轴,一个编辑文本和一个按钮

我想要这样,当在 axes_1 上单击鼠标时,我得到位置并使用 X 位置更新编辑文本。

在打开函数中我放了以下内容

set(handles.axes_1, 'ButtonDownFcn', @axes_1_ButtonDownFcn);

在 axes_1_ButtonDownFcn 我放了

pos=get(hObject,'CurrentPoint');
disp(['You clicked X:',num2str(pos(1)),', Y:',num2str(pos(2))])
handles.value= pos(1);
set(handles.edit1,'String',handles.value);

但给我以下错误

对不存在的字段“edit1”的引用。 trytool>axes_1_ButtonDownFcn 中的错误(第 198 行) set(handles.edit1,'String',handles.value);

评估轴 ButtonDownFcn 时出错

edit1是编辑文本的标签名,不是拼写错误之类的,为什么函数不能识别编辑文本?

非常感谢!

【问题讨论】:

  • 你能调试和显示handles结构中实际包含的内容吗?这可能会给你一个提示。

标签: matlab user-interface matlab-guide


【解决方案1】:

我尝试使用您的代码构建一个 GUI,如果您将添加到打开函数的代码注释掉,它会很好地工作:

%set(handles.axes_1, 'ButtonDownFcn', @axes_1_ButtonDownFcn);

【讨论】:

  • @DiegoFernandoPava 我认为您会收到错误消息,因为在 openingfcn 中可能尚未创建轴,因此您正在设置不存在控件的属性。此外,您不需要该代码,因为您已经为轴定义了 ButtonDownFcn,您在编写 ButtonDownFcn 回调时设置了它。
猜你喜欢
  • 1970-01-01
  • 2014-10-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-17
  • 2013-04-14
  • 1970-01-01
相关资源
最近更新 更多