Getting an equation into a numeric text field in App Designer
9 次查看(过去 30 天)
显示 更早的评论
I'm creating an app that based on getting an equation from the user + some values that includes real numbers and characters, the program will perform some calculation based on those inputs, then print out the result into a label.
How can I retrieve an input like this one: x-x.^(1/3)-2?
Do I have to retrieve it as a text? like this?
func = num2str(app.func.Value);
What if I need the app to identify some constants like the e (2.71828) number for example, which means what if I need to get this input from the user: 1e-6, what would I need to add in the code to make this input acceptable?
What is the correct way to retrieve those inputs?
Cause the algorithm that I'm using is working fine in Matlab command window, but the same algorithm is not giving a correct result when I tried it in the App designer.
It is because of the way I'm using to retrieve the inputs?
Here is the algorithm I'm using in App Designer:
func = num2str(app.func.Value);
a = (app.num1.Value);
b = (app.num2.Value);
error = (app.errortol.Value);
fx = 2*error; n = 0;
while ((abs(fx)>(error) ) & (n<=100) )
n=n+1;
x=a;
fa=eval(func);
x=(a+b)/2;
fx=eval(func);
if (fx*fa > 0)
a=x;
else
b=x;
end
end
result = eval(func);
app.solution.Text=num2str(x);
I keep getting an integer number in the solution label, while I suppose to get a real number.
0 个评论
回答(1 个)
另请参阅
类别
在 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!