Grab and reference data from OpeningFcn?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
rbme17
el 17 de Jul. de 2017
Comentada: rbme17
el 17 de Jul. de 2017
Hi,
I was wondering if there's a way to call data from OpeningFcn in a Matlab GUI. I need to reference an initialized value in OpeningFcn to one that's updated with the user input once a pushbutton is pressed.
The initialized data (xi) is compared to the user's gui input _(xgui). If they're not equal, an if statement will run.
if xi ~= xgui
xi = xgui
for ...
...(some other code)...
end
end
I've tried creating variables and structures in OpeningFcn, referencing it using handles.OpeningFcn, but I can't seem to figure it out. Can someone please help?
Thanks!
0 comentarios
Respuesta aceptada
Geoff Hayes
el 17 de Jul. de 2017
rtbme17 - if you have (for example) variables in your OpeningFcn that you want to reference later, then save them to the handles structure. For example,
function GUI_OpeningFcn(hObject, eventdata, handles, varargin)
% do some stuff
x = 42;
% save x to the handles structure
handles.x = x;
guidata(hObject, handles);
Note that the guidata(hObject, handles); is important as it will save the updated handles structure so that all other callbacks have access to this updated structure (and so can access x). Then in some callback you would do
function pushbutton1_Callback(hObject, eventdata, handles)
% use x
if isfield(handles, 'x')
y = handles.x * 2;
% etc.
end
In the above, we check to see if x is a fields within handles before trying to use it.
Más respuestas (0)
Ver también
Categorías
Más información sobre Environment and Settings en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!