Break a while loop in a GUI Pushbutton
Ältere Kommentare anzeigen
Hi there,
I have a GUI set up and it has a Start pushbutton and a Stop pushbutton. Upon pushing the start, data is transmitted and received between AVR and matlab with Serial communication.
What I am trying to do is while the data is communicated and being run, if the stop button is pressed, the while operation should stop. This should be accomplished if I can just break the while loop, but the code that I've tried using 'assignin' and 'evalin' hasn't succeeded. Actually it occasionally works but sometimes doesn't work. Here is what my code :
function StartButton_Callback(hObject, eventdata, handles)
flag = 0;
assignin('base','flag', flag);
bt = Bluetooth('JCNET-BT-7827',1);
fopen(bt);
while 1
%%Receiving and Display Serial Communication
flag = evalin('base', 'flag');
if flag == 1
break;
end
end
When the EndButton is pressed,
% --- Executes on button press in EndButton.
function EndButton_Callback(hObject, eventdata, handles)
flag = 1;
assignin('base','flag', flag);
Could anyone give me for advices? Thanks a lot in advance!
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Interactive Control and Callbacks finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!