0

I have the following code as part of my MATLAB GUI code:

k = waitforbuttonpress;
if k==0               
   if strcmp(get(handles.YESNO,'String'),'Y')

        hint = 1;
    else
        hint = 0;
    end                
else
    hint = 0;
end

I wait for the user to press one of the two YES or NO buttons. Inside each of these callbacks I update the variable handles.YESNO as set(handles.YESNO,'String','Y'); or set(handles.YESNO,'String','N'); respectively.

When I execute my MATLAB GUI, I have to press the YES button twice for the value to take into effect. Any tips/hints to overcome this issue?

Dhiraj
  • 13
  • 2
  • This is what I have in my YES Callback.. function YES_Callback(hObject, eventdata, handles) set(handles.YESNO,'String','Y'); guidata(hObject,handles) – Dhiraj Oct 13 '15 at 18:24
  • [Use the debugger](http://www.mathworks.com/help/matlab/matlab_prog/debugging-process-and-features.html). – sco1 Oct 13 '15 at 18:41

1 Answers1

0

I believe that the waitforbuttonpress mask your callback. Instead, block your executation with uiwait that waits for your figure to close or to uiresume called by the buttons callbacks.

Lior Cohen
  • 5,570
  • 2
  • 14
  • 30
  • I did not completely understand what you mean, but when I use the debugger and put breakpoints it works fine. But it does not in actual runtime. Probably "... mask your callback" is whats happening (if that is a thing). So uiwait is called to wait for user input and uiresume should be put inside the callbacks? – Dhiraj Oct 13 '15 at 22:09