Stop the iteration when a button got pressed in MATLAB App Designer
5 views (last 30 days)
Show older comments
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 Comments
Answers (1)
Sourabh Kondapaka
on 4 Sep 2020
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 Comments
See Also
Categories
Find more on Develop Apps Using App Designer in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!