Stop the iteration when a button got pressed in MATLAB App Designer
조회 수: 4 (최근 30일)
이전 댓글 표시
I'm currently developing an App which computes the roots for a given function, there is a solve button which computes the solution to the function, the output of each iteration will be presented in a table.
Now, I want to add a stop button which will stop the iteration whenever the stop button is preseed.
How can I call the stop button inside the start button to stop the iteration?
And what I have to add inside the stop function to make it work?
Here's the start button:
fun = app.EditField.Value;
a = app.EditField_2.Value;
b = app.EditField_3.Value;
error = 1.0*10.^-5;
syms x;
func = matlabFunction(str2sym(fun));
devfunc = matlabFunction(diff(func(x)));
if (app.EditField.Value == " " && app.EditField_2.Value == " " && app.EditField_3.Value == " " && app.EditField_4.Value == " ")
%Error Alert
else
fu = 1.0*10.^-5;
num = 0;
while ( abs(fu) >= error || num < 10)
num = num + 1;
c = (a+b)/2;
cr = c - func(c)/devfunc(c);
if a < cr
xi = cr;
else
xi = c;
end
fu = func(xi);
if func(a)*fu < 0
b = xi;
vars = {num2str(num), num2str(xi),num2str(func(xi))};
app.UITable.Data = [app.UITable.Data; vars];
else
a = xi;
vars = {num2str(num), num2str(xi),num2str(func(xi))};
app.UITable.Data = [app.UITable.Data; vars];
end
end
end
app.Root.Text = num2str(xi);
![Improved.png](https://www.mathworks.com/matlabcentral/answers/uploaded_files/247289/Improved.png)
댓글 수: 0
답변 (1개)
Sourabh Kondapaka
2020년 9월 4일
Hi,
I would suggest using a “timer()” function within “StartButtonPushed(app, event)” method to execute.
Within the callback function of the timer object you can implement your functionality on calculating the roots of the equation.
When “StopButtonPushed(app, event)”method is called, you can delete or stop the timer.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Workspace Variables and MAT-Files에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!