Getting an equation into a numeric text field in App Designer

4 Ansichten (letzte 30 Tage)
T.Mariah Khayat
T.Mariah Khayat am 12 Okt. 2019
Beantwortet: Ajay Kumar am 12 Okt. 2019
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.

Antworten (1)

Ajay Kumar
Ajay Kumar am 12 Okt. 2019
doc format
Use format long before computing x.

Kategorien

Mehr zu Develop Apps Using App Designer finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by