フィルターのクリア

How to have multiple GUI functions access varargin?

3 ビュー (過去 30 日間)
John F
John F 2016 年 3 月 7 日
回答済み: Geoff Hayes 2016 年 3 月 7 日
Is there a way to have all the functions in a GUIDE-based GUI access the input arguments to the function? I've done this by creating global variables for each of the input arguments so all the other functions have access to them. I'm wondering if there is a different way without creating globals.
Thanks!

回答 (1 件)

Geoff Hayes
Geoff Hayes 2016 年 3 月 7 日
John - rather than using global variables, why not save the input parameters to the handles structure? Presumably, you are accessing your input parameters in the OpeningFcn of your GUI so you could do something like
function GuiSaveDataExample_OpeningFcn(hObject, eventdata, handles, varargin)
% Choose default command line output for GuiSaveDataExample
handles.output = hObject;
if length(varargin) > 1
handles.input1 = varargin{1};
handles.input2 = varargin{2};
end
% Update handles structure
guidata(hObject, handles);
The order in the above is important - we read the (for example) two input parameters and store each in fields named input1 and input2 (you can name these to whatever they represent) and then call guidata to save the updated handles structure. As the third input to each callback is (typically) handles, then each callback has access to these input parameters.
Try the above and see what happens!

カテゴリ

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

製品

Community Treasure Hunt

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

Start Hunting!

Translated by