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

6 ビュー (過去 30 日間)
Aqilah Asri
Aqilah Asri 2022 年 5 月 23 日
回答済み: Nivedita 2023 年 9 月 20 日
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 Center および File ExchangeFunction Creation についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by