MATLAB: How to get updated value of UI toggle button, within it’s callback function

callbackguihandlestoggle button

I want to use a toggle button as an on of switch. So when the button is pressed, the work is done untill the button is depressed. But in my code, the button depress doesn't work because 1st callback (when button pressed) is still being executed, and without the second callback, the Value isn't updated.
function togglebutton1_Callback(hObject, eventdata, handles) % hObject handle to togglebutton1 (see GCBO) % eventdata reserved – to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of togglebutton1
while (get(hObject, 'Value') == get(hObject,'Max'))
_..do the work.._
end

Best Answer

If you set the 'Interruptible' property to 'off' and allow Matlab to react to actions using drawnow, the button should change its value.