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!