How to interrupt a while loop in Appdesigner by pushing a button?

I'm using appdesigner in 2016a.I have two buttons. One is for starting a while loop and the other is for stopping that loop.But the old method
set(handles.buttonA, 'UserData', 'stop');
is not working for me. what else can I use in appdesigner? Thanks for answering!

댓글 수: 5

Victor Lahore's answer moved here
I Have the same problem:
while 1==1
value = app.Iniciar_button.Value
if value == 'off'
break
end
end
But the button value does not refresh
Victor - try putting a pause or drawnow statement in your while loop (after the if block) so that the loop is interruptible.
An interrupt can only occur at one of these commands...
When an object's Interruptible property is set to 'on', its callback can be interrupted at the next occurrence of one of these commands: drawnow, figure, getframe, waitfor, or pause.
I usually set pauses in several places within a function to give the push button interrupt a chance to execute. i.e. pause(.00001)
Thank you, Brian.
A pause in the loop after if block works very well, that helps a lot. Thanks.

댓글을 달려면 로그인하십시오.

 채택된 답변

Geoff Hayes
Geoff Hayes 2016년 6월 19일

2 개 추천

Helen - what can you tell us about your while loop? Does it have a pause or drawnow function call? If it doesn't then it is not interruptible and so the callback for the second pushbutton to stop the while loop will not be executed.

댓글 수: 2

I don't use pause or drawnow function. I want to do real-time signal process with Audio Systems Toolbox like this
while 1
mySignal = record(deviceReader);
myProcessedSignal = process(mySignal);
play(deviceWriter, myProcessedSignal);
end
but now I can only use tic and toc to control the while loop just like the example code.
Helen - I would put a small pause as the final line of your while loop so that the other callback has a chance to execute. Though will that matter given that the while condition is always true? How do you expect to exit the loop?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Create Large-Scale Model Components에 대해 자세히 알아보기

제품

질문:

2016년 6월 18일

댓글:

2020년 12월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by