I am new to GUI programming for MATLAB, so my question relates to that.
Let's say that I create a GUI with GUIDE. In the creation function
MyGUI_OpeningFcn(hObject, eventdata, handles, varargin)
I call another function,
SamplingRate_Callback(handles.SamplingRate, eventdata, handles)
defined as
function SamplingRate_Callback(hObject, eventdata, handles)
SamplingRate_Callback sets a few variables,
handles.a = 1;
handles.b = 2;
handles.c = 3;
The handles
structure updates correctly within the SamplingRate_Callback
function. The problem I am having is that unless I change the function to
function handles = SamplingRate_Callback(hObject, eventdata, handles),
I cannot return the data to the calling function, MyGUI_OpeningFcn
. I have tried using guidata(gcf, handles)
and guidata(hObject, handles)
, but neither works.
Would you be able to shed some light on this problem?
Also, I am not sure when to use guidata(gcf, handles)
vs. guidata(hObject, handles)
.
Thanks for your help!