How to have multiple GUI functions access varargin?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
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!
0 comentarios
Respuestas (1)
Geoff Hayes
el 7 de Mzo. de 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!
0 comentarios
Ver también
Categorías
Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!