Making STOP - Button
古いコメントを表示
Hi everybody! I'm new here and have a question about GUI's.
I have a GUI which contains (among other things) two (push)buttons. The first one is a "Start" button and the second one should be some kind of a "Stop" button. By pressing "Start" an infinite loop begins and the program starts reading a certain amount of data from a port and saves it to a file. When it finished reading it waits a few seconds and starts reading again. This happens x times, where x is a predifined value.
Now I want, that pressing the "Stop"-Button forces the program to stop at n < x runs (n depending on when I press the button).
For that purpose I defined a variable "run", which is 1 and gets 0, when "Stop" is pressed. So an exit is possible.
That's the plan. Unfortunatelly that doesn't work. I assume, that the rest of the GUI is "frozen" while the program is stuck in the loop, so pressing "Stop" doesn't change anything. I supposed pressing the button triggers some kind of interrupt, so being stuck in the loop is no problem, but sadly it seems as I am wrong (or I have to enable the interrupt, without knowing how). I already read a related post, where the questioner was advised to use a checkbox instead, but sadly this is no option for my purpose.
I hope some of you can help me? :)
Thank you!
1 件のコメント
Antonio De lavalle
2021 年 4 月 22 日
移動済み: Rik
2023 年 3 月 4 日
excuse a doubt I need to make a music note player but they also ask me to incorporate a pause button in the program
採用された回答
その他の回答 (1 件)
Rik
2018 年 7 月 20 日
I use a uicontrol togglebutton in such cases:
%in your looping code:
if get(handles.togglebutton,'Value')
break
end
%in the callback of the button:
set(hObject,'Value',1)
2 件のコメント
noNickame
2018 年 7 月 23 日
Rik
2018 年 7 月 23 日
You indeed need to reset the togglebutton value when you start your code. You could use a normal pushbutton instead, but that means that you need to be very careful where you load and reload your guidata.
So at the start of you looping function (before you enter the loop), you'll need to set(handles.togglebutton,'Value',1), and then it should work.
PS you see why I don't use GUIDE: a forest of functions calling each other in a convoluted way. Really difficult to understand where you should make changes.
カテゴリ
ヘルプ センター および File Exchange で Interactive Control and Callbacks についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!