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

5 ビュー (過去 30 日間)
T.Mariah Khayat
T.Mariah Khayat 2019 年 11 月 7 日
回答済み: Sourabh Kondapaka 2020 年 9 月 4 日
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

回答 (1 件)

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

カテゴリ

Help Center および File ExchangeDevelop Apps Using App Designer についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by