How to enter an input in an active 'while' loop?

9 Ansichten (letzte 30 Tage)
David Mason
David Mason am 4 Jul. 2011
Hi everybody,
I want to 'break' a 'while' loop when an input gets a specific value. Unfortunately, I don't know why when I change the input value, (when 'while' loop is executing), the 'while' loop doesn't recognize! this change?
Please guide me..
Thanks, David

Akzeptierte Antwort

Paulo Silva
Paulo Silva am 9 Jul. 2011
Take a look at my program SpSpj , might not be the best way to do it but it does work
  1 Kommentar
David Mason
David Mason am 9 Jul. 2011
Thanks Paulo,
My problem was that I expected to MATLAB understands handles.xxx variable! (even though I used 'guidata(hObject, handles)' in callback of my button)
but your suggestion to use 'global' variable nicely works.
Thanks

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Oleg Komarov
Oleg Komarov am 4 Jul. 2011
x = 1;
while x == 1
x = input('Value for x: ');
end

David Mason
David Mason am 9 Jul. 2011
Oleg,
Thanks for the response, but I didn't mean this type of input (using 'input' func.). Let's assume I want to run a 'while' loop and terminate it when I press a push button key on my GUI! Could you please suggest me something else?
Thanks
Others' comments are welcome.
  1 Kommentar
Oleg Komarov
Oleg Komarov am 9 Jul. 2011
instead of x == 1 you can verify that the button has been pushed.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by