필터 지우기
필터 지우기

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 CenterFile Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by