May I know why 'value must be a double scalar' come out in app designer?

1 次查看(过去 30 天)
syms x
f_bisection = app.EquationEditField.Value;
f2_bisection = str2sym(f_bisection);
a=app.aEditField.Value;
b=app.bEditField.Value;
iteration=1;
itemax = 70;
if f_bisection(a)*f_bisection(b)>0
disp('Wrong choice')
else
x=(a+b)/2;
while iteration < itemax
if f_bisection(a)*f_bisection(x)<0
b=x;
else
a=x;
end
x=(a+b)/2;
iteration=iteration+1;
end
end
app.RootEditField.Value = x;

回答(1 个)

Nivedita
Nivedita 2023-9-20
Hello Aqilah!
I understand that you are receiving the error “ 'Value' must be a double scalar” in app designer.
I am assuming that this error is thrown for the last line:
app.RootEditField.Value = x;
There are two types of edit fields in app designer: numeric and text. Numeric edit fields only receive double scalar values. Since “x” is a symbolic variable, MATLAB is rejecting the value and throwing the error.
You can convert “x” into a double scalar using the “double” function and assign it to “RootEditField” in the following manner:
app.RootEditField.Value = double(x);
For more information on the “Value” property of “NumericEditFields” in app designer and the “double” function, you can refer to the following documentation links:
  1. NumericEditField.Value: https://www.mathworks.com/help/releases/R2021b/matlab/ref/matlab.ui.control.numericeditfield-properties.html#:~:text=Value%20%E2%80%94%20Value%20in%20edit%20field
  2. double: https://www.mathworks.com/help/releases/R2021b/symbolic/double.html
I hope this helps!
Regards,
Nivedita.

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by