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

1 visualizzazione (ultimi 30 giorni)
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;

Risposte (1)

Nivedita
Nivedita il 20 Set 2023
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.

Categorie

Scopri di più su Function Creation in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by