How to have multiple GUI functions access varargin?

1 vue (au cours des 30 derniers jours)
John F
John F le 7 Mar 2016
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!

Réponses (1)

Geoff Hayes
Geoff Hayes le 7 Mar 2016
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!

Catégories

En savoir plus sur Migrate GUIDE Apps dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by