简体   繁体   English

MATLAB指南

[英]GUIDE in MATLAB

I am trying to build a program in MATLAB and I am using edit boxes but I want the value that the user will enter to be used later on from another function. 我正在尝试在MATLAB中构建一个程序,我正在使用编辑框,但我希望用户输入的值稍后将从另一个函数中使用。 So should I use the global variables or is there another way? 那么我应该使用global变量还是有另一种方式?

I tried to define the global variables outside the function but is not working. 我试图在函数外部定义global变量但不起作用。 I tried to define it inside the function and then call it from another function but it says that it is undefined. 我试图在函数内部定义它,然后从另一个函数调用它,但它说它是未定义的。 Is there a way that I can do that? 有没有办法可以做到这一点?

I am just using 我正在使用

function edit1_Callback(hObject, eventdata, handles)
str2double (get (hObject,'String'));

Thanks!! 谢谢!! :) :)

If you want to store data within a Matlab-GUI, you can use the handles-structure like this: 如果要在Matlab-GUI中存储数据,可以使用handle-structure,如下所示:

handles.myVar=123;
%after this dont forget to save it (yes, this is a bit annoying):
guidata(hObject, handles);

later on, within another callback for example, you can find this data within the handles-struct: 稍后,在另一个回调中,例如,您可以在handles-struct中找到这些数据:

handles.myVar

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM