Stop the iteration when a button got pressed in MATLAB App Designer
1 次查看(过去 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);

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 中查找有关 Develop Apps Using App Designer 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!