My 'while' loop no longer recognizes stop.

This used to work:
while ( strcmp(get(hObject,'String'),'Stop') )
stuff
end
This while loop for running an animation is in the callback for a GUI button that changes between 'Start' and 'Stop' when pressed.
It used to be that the button was enabled during the execution of the 'while' loop, such that pushing the button again would stop the animation.
In R2016b, that no longer seems to be the case.
==> Is there a way for GUI buttons to be enabled during a callback 'while' loop, or is there another kind of loop that can be aware of changes so that it can be interrupted?

5 Kommentare

Rik
Rik am 2 Nov. 2017
I am using a very similar trick to interrupt a long looped calculation and I have no problems on R2017b or R2012b. So are you sure nothing else changed? Have you tried what output that get is giving you when you don't use a loop?
Inside the loop I would also like to have a check box to turn on or off the display of violations of a boundary.
It doesn't matter whether I ask to check the status of the check box or not, it still doesn't update until the while loop is complete:
BoundBoxCk_Callback(hObject, eventdata, handles)
ckVal = get(handles.BoundBoxCk,'Value');
if ckVal
Violations = ckEnvel(Envelope, BndryDat);
end
I can see the ckBox value scrolling during the while loop, and it doesn't recognize the change until the while loop is done. After that, the check box works fine.
It may be that 2017b works the way I intended, but that 2016b is different. This used to work. I am not sure what version I was using before when it did.
Rik
Rik am 2 Nov. 2017
It is very unlikely this works in R2012b and R2017b, but not R2016b.
I did use a callback to set a value. You can even store a boolean in the struct you save in guidata (don't forget to reload your guidata every loop iteration if you go down that path).
I've had the following in the while loop all along.
guidata(hObject,handles) % post handles data via guidata
handles = guidata(gcbo); % update values from GUI interface
I've also tried accessing handles.ckVal directly, assuming that checking the box during the while loop would set the values of handles.ckVal for other callbacks to use.
The callback for the check box is the following:
function BoundBoxCk_Callback(hObject, eventdata, handles)
%%BoundBoxCk_Callback Executes on button press in BoundBoxCk.
handles.ckVal = get(hObject,'Value');
guidata(hObject,handles)
Rik
Rik am 2 Nov. 2017
You are storing handles before reloading it, which will overwrite any changes made in a callback.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Walter Roberson
Walter Roberson am 2 Nov. 2017

0 Stimmen

You do not appear to have a drawnow() or pause() or uiwait() or waitfor() or figure() to allow the graphics queue to be flushed to permit the interrupt of clicking the button to be serviced.

Kategorien

Gefragt:

am 2 Nov. 2017

Beantwortet:

am 2 Nov. 2017

Community Treasure Hunt

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

Start Hunting!

Translated by