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

조회 수: 1 (최근 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 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