Matlab GUIDE push button does not get updated handle

3 views (last 30 days)
I have Matlab GUI that has few text box edits and pushbutton.
Basically, when GUI runs, entering and changing the values in text box corresponding to min, max and res snr variables (see code)shows me the change, but as soon as I enter the pushbutton dialog box, the changed values( that were captured in global variable "handles") do not show up as I break in the code there.
I would expect that a change in edittextbox callback ,captures in"handles", would be seen in any other callback too?
please see the code attached.
Thank you
sedy

Accepted Answer

Geoff Hayes
Geoff Hayes on 17 Jun 2015
Sedy - how are you verifying that the values are not changing? (You did not attach any code. You must press the Attach File button once choosing the file.)
Remember, the handles structure has handles to the controls (like the edit text box) so you should use the control handle to retrieve the value. For example, suppose the following is your push button callback
function pushbutton1_Callback(hObject, eventdata, handles)
% get the text value for edit text 1
val = get(handles.edit1,'String');
% etc
So val is initialized to the string contents of the edit text box.
However, if you are saving data to the handles in another callback (which you seem to imply) then you must call the guidata function to ensure that the modified handles structure is updated so that all other callback receive the updated structure. For example
function edit1_Callback(hObject, eventdata, handles)
% do something
% update handles
handles.snr = 42.1;
guidata(hObject,handles);
Note the call to guidata after handles has been modified.
  1 Comment
sedy
sedy on 17 Jun 2015
Edited: sedy on 17 Jun 2015
Thanks. I forgot to put in
guidata(hObject,handles);
in edit text box callbacks, while I did for others.
sedy

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!