如何从其他功能访问 GUIDE 图上的控件?
我正在使用 GUIDE
为我的 MATLAB
项目创建一个 GUI
。
在按钮的一个回调中,我调用了一个函数。
[Name]= otherFunction(inputVariable);
set(handles.name,'String',Name);
收到该函数的输出后,我将名称标签设置为 Name 的值。是否可以从函数内部进行设置?我需要做什么才能允许该函数访问 GUIData?
我尝试过从该函数内部使用 set/get 但我似乎无法让它工作。
或者,我是否可以使“句柄”在全球范围内可用?
I am using GUIDE
to create a GUI
for my MATLAB
project.
In one of my callbacks for a button, I call a function.
[Name]= otherFunction(inputVariable);
set(handles.name,'String',Name);
After I receive the output from that function, I set the name label to the value of Name. Is it possible to set that from inside the function? What do I have to do to allow that function to access the GUIData?
I have tried using set/get from inside that function but I can't seem to get it to work.
Alternatively, is there anyway that I can make the 'handles' globally available?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从一个空白的 GUI 开始,简单地向其中添加一个按钮(标记为“btnTest”),以下代码可以正常工作:
因此,您的代码中可能还有其他问题。
如果您不打算将“handles”结构传递给“changeName”函数(即具有全局可用的句柄),您可以这样做:
但它比直接传递“handles”慢得多。
Starting from a blank GUI and simply adding a pushbutton to it (tagged as 'btnTest'), the following code works fine:
So there's probably something else wrong in your code.
If you intend not to pass the 'handles' structure to the 'changeName' function (i.e. have handles globally available), you can do it like this:
But it's much slower than passing 'handles' directly.