How to use variables from my GUI in my function?

1 回表示 (過去 30 日間)
MechE1
MechE1 2018 年 7 月 24 日
コメント済み: OCDER 2018 年 7 月 24 日
I have a GUI with text boxes and pop up menus, but I'm having trouble trying to save the output variables and then using them within my function. I call upon the GUI in my function but the code executes before I even get to choose my options from the GUI! I'm not very familiar with GUIs some explanation would be appreciated! Thank you in advance.
  1 件のコメント
MechE1
MechE1 2018 年 7 月 24 日
Is this bad formatting? if so, does my .m file have to be within the GUI to work?

サインインしてコメントする。

採用された回答

OCDER
OCDER 2018 年 7 月 24 日
Seems like you're using GUIDE?
You have to uncomment the uiwait(handles.figure1) in the OpeningFcn. Otherwise your GUI will close out before you can do anything. You also need to use uiresume in each Callback function to ensure your uiwait coding execution blockage is lifted.
To see an example, do the following:
1) >> guide
2) In guide setup, Create New GUI -> Modal Question Dialog -> OK
3) Look at the .m file for CloseRequestFcn, OpeningFcn, CallBack, OutputFcn
  3 件のコメント
Stephen23
Stephen23 2018 年 7 月 24 日
編集済み: Stephen23 2018 年 7 月 24 日
"Is placing my function within the original GUI the only option available?"
It is not required that your function be written in the GUI Mfile: it needs to be on the MATLAB path, just like any other function.
"Or can I call the GUI from my function and somehow save the variables after everything is set and done?"
Uncomment waitfor. Call the main GUI function with input and output arguments.
OCDER
OCDER 2018 年 7 月 24 日
You need to modify the OutputFcn to save the variables you need for the next GUI.
MainGUI -> PushButton calls SubGUI -> User inputs data and pushes DONE -> SubGUI's OutputFcn must extract all the values and return it as a structure or something -> MainGUI accepts this outputs of SubGUI
EXAMPLE
%MainGUI's callback function
function pushbutton1_Callback(hObject, eventdata, handles)
Out = SubGUI;
... do somethig with the output
end
%SubGUI's output function
function varargout = testGUI_OutputFcn(hObject, eventdata, handles)
varargout{1} = handles.edit1.String;
varargout{2} = handles.edit2.String;
end

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeEntering Commands についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by