필터 지우기
필터 지우기

How to stop a loop using a push button?

조회 수: 4 (최근 30일)
DEVESH DANGI
DEVESH DANGI 2018년 4월 24일
답변: Ameer Hamza 2018년 4월 24일
I have created a GUI added axes with two push button.The first push button is for starting the function which takes values from Arduino and plots it and the second button is for stopping the graph which is currently being plotted. I also want that if I again push that first button then it will again start plotting.
I have done the plotting part but I am unable to do the stopping part.
  댓글 수: 2
Ameer Hamza
Ameer Hamza 2018년 4월 24일
How are you plotting the graph? Is there a callback function or loop which is running to plot the graph.
DEVESH DANGI
DEVESH DANGI 2018년 4월 24일

Yes, I have used two axes but it wont matter. I only wanted to know that how to stop the graphs being plotted.

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

답변 (1개)

Ameer Hamza
Ameer Hamza 2018년 4월 24일
In your code, you are running an infinite loop inside callback of push-button. Callback functions are intended to only perform a specific task, no to continue execution forever.
Here is a solution based on timer callback function inside App designer. You can start a timer which will update app.UIAxes after every a specific period of time (say 0.5 seconds). Now to start and stop the plotting, you can use UserData property present in every graphics object handle. This property is not used by MATLAB and only for the user to save extra information. You can use this property to convey a message between callbacks about whether you want to plot or not. The timer callback function will only plot if app.UIAxes.UserData = 1, otherwise stop plotting. The start push button callbacks will set app.UIAxes.UserData = 1 while stop pushbutton callback will set app.UIAxes.UserData = 0.
Mathwork does not allow attaching mlapp files, therefore, I have uploaded it here. You can look at Code View and get an idea of how to modify the code for your own app.

카테고리

Help CenterFile Exchange에서 Specifying Target for Graphics Output에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by