loop while in a GUI stopped by callback

hello everybody, I'm french so excuse me for my english. I'm doing a GUI and I want to do a loop while which has to stop when a checkbox called TR is checked :
while (get(handles.TR,'Value'))
.
.
.
end
But in the loop, matlab don't receive the callback and the value of the checkbox is not changed I don't know how I have to do....
thank you for your help

Risposte (4)

Fangjun Jiang
Fangjun Jiang il 17 Ago 2011
The computer will be running the while loop and be too busy to process your click on the checkbox. Add a pause(1) line in the while loop might help.
No no I want to stop it when the Value is 0. the problem is that there is no change, I've do :
while (get(handles.TR,'Value'))
get(handles.TR,'Value') % without ; to see the answer
end
and even when I click on the checkbok the answer is always 1
Jan
Jan il 17 Ago 2011
MATLAB processes events as mouse clicks when the program returns to the command line, a DRAWNOW or PAUSE command. While PAUSE wastes some time (except for PAUSE(0)...), DRAWNOW is the best choice:
while (get(handles.TR,'Value'))
.
.
drawnow;
end
trajik
trajik il 17 Ago 2011
I've tested whit drawnow, and I think that it stop the loop whatever the while's condition and the mousse click(it's not a problem),it's right??

1 Commento

I made a quick test. Both pause() and drawnow() works. drawnow() is a better choice. Hope you understand the underline cause now.

Accedi per commentare.

Categorie

Scopri di più su Graphics Performance in Centro assistenza e File Exchange

Richiesto:

il 17 Ago 2011

Community Treasure Hunt

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

Start Hunting!

Translated by