Effacer les filtres
Effacer les filtres

Stop the iteration when a button got pressed in MATLAB App Designer

4 vues (au cours des 30 derniers jours)
T.Mariah Khayat
T.Mariah Khayat le 7 Nov 2019
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

Réponses (1)

Sourabh Kondapaka
Sourabh Kondapaka le 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.

Catégories

En savoir plus sur Workspace Variables and MAT-Files dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by