MATLAB: Togglebutton Problem

guiguidematlab guipush button

I am trying to use a toggle button in a project that I am working on and I am having trouble with the button it seems. I would like to execute certain code as long as the button is depressed (or the state is 1). However, it seems that the code goes into an infinite while loop. When I tried to check the state of the button as I pressed it, only 1's appeared and teh state did not change. Here is the simple code taht I am working with:
while Button == get(hObject,'Max')
EXECUTE CODE
if get(hObject,'Min')
break;
end
end
Any help is greatly appreciated!

Best Answer

You have to get() the Value of hObject. The Max and Min values do not change (not unless you specifically change them.)
Also, be sure that something in your code gives an opportunity for the GUI to react to events.
bmax = get(hObject, 'Max');
while get(hObject, 'Value') == bmax
EXECUTE CODE
drawnow(); %allow events
end