How to use varargout in a GUI

9 ビュー (過去 30 日間)
Simon Aldworth
Simon Aldworth 2018 年 10 月 23 日
コメント済み: Walter Roberson 2018 年 10 月 24 日
Hi,
There is clearly something I don't understand about getting data from a gui into my main code. For the purposes of an example, I created a gui using GUIDE that contained a single edit box that I left exactly as it was created. In the automatically generated code are lines in OpeningFcn that define handles.output and update guidata:
function dummy_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for dummy
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
Then, in the OutputFcn, varargout{1} is set equal to handles.output:
function varargout = dummy_OutputFcn(hObject, eventdata, handles)
% Get default command line output from handles structure
varargout{1} = handles.output;
When I run the gui I don't see any variables in the main workspace. What is varargout for if not to pass data to the main workspace? Is there something missing from the automatically generated code that I need to insert so I can access handles.output in the main workspace?
Thanks,
Simon.
  13 件のコメント
Stephen23
Stephen23 2018 年 10 月 24 日
編集済み: Stephen23 2018 年 10 月 24 日
@Simon Aldworth: avoid using assignin, or any other method that magically makes data appear or disappear from another workspace. Read this to know some of the reasons why:
Beginners often seem to love making data appear and disappear because they like to see all of their data in the base workspace. Experienced users handle all of the data within the GUI itself, which also leads to simpler, more robust, more efficient, less buggy code.
If you really want to return values to the base workspace then either use nested functions and waitfor (if you are sensibly writing your own GUI), or use the OutputFCN (if you are unfortunately using GUIDE).

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeMigrate GUIDE Apps についてさらに検索

製品


リリース

R2017b

Community Treasure Hunt

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

Start Hunting!

Translated by