how to stop a loop with a button in GUI
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a have that reads data from a device. I have made a GUI with GUIDE with a 'Read' and 'Stop Read" button.
The program contains a callback function for the Read, and the stop button and the Read callback uses the f_Read() function to read the data. I want the program to stop executing f_Read when i press the stop button. I was thinking that the while loop could evaluate handles.stop == 0, so that while handles.stop = 0, f_Read() will be executed, and then when i press the stop button handles.stop =1 and the while loop would stop. But it seems like it doesnt discover that handles.stop = 1, when i press the stop button, and therefore it just keeps executing f_Read(). What am i doing wrong? Or should i do it in a different kind of way?
function Read_button_Callback(hObject, eventdata, handles)
%Executes when the 'Read data' button is pressed, and lets the program
%read data from the smartbox
handles.stop=0
while handles.stop == 0
[data] = f_Read(2,2)
end
display('stopped')
return
function Stop_button_Callback(hObject, eventdata, handles)
%executes when the 'Stop' button is pressed
handles.stop = 1
댓글 수: 0
답변 (1개)
Sean de Wolski
2012년 1월 16일
Please see my answer to this question:
댓글 수: 1
Daniel Shub
2012년 3월 20일
Depending on how f_Read is implemented, the timer may not be able to break into such a simple loop. It is also not clear that handles is really a handle object, so the timer callback setting handles.stop might not break the loop.
참고 항목
카테고리
Help Center 및 File Exchange에서 Migrate GUIDE Apps에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!