필터 지우기
필터 지우기

Error using matlab.ui.​control.Ed​itField/se​t.Value 'Value' must be a character vector or a string scalar.

조회 수: 70 (최근 30일)
Hi,
I got a question about app deisgner. I am using 2 edit fields (text). The first one is to write a value (e.g : 2). For the second I would like matlab to calculate directly (without action) the multiplication of the first edit field by 3,6. I am using edit field (text) instead of edit field (num) because edit field (text) allow the "Value changing function".
In the last line of the code below, matlab says " Error using matlab.ui.control.EditField/set.Value 'Value' must be a character vector or a string scalar." The first edit field is called "SCx" and the second is "A2".
function SCxEditFieldValueChanging(app, event)
value = event.Value;
value2 = value+3;
app.A2EditField.Value = value2;
end
Need help to understand my mistake or to help me find a solution.
Thanks,
Max-Henri Froger

채택된 답변

Tommy
Tommy 2020년 4월 24일
value as obtained from event.Value is a character vector, so adding 3 to it does not do what you may think it does:
>> '4'+3
ans =
55
Then, value2 is a double, so you cannot use it to set app.A2EditField.Value, which must be a character vector or string scalar as the error message indicates. Try this:
value2 = num2str(str2double(value)+3);
  댓글 수: 3
Shelynna Adjana Banawe
Shelynna Adjana Banawe 2023년 6월 20일
i've similar issue but i used number field instead of text
a = app.val1.Value;
b = app.val2.Value;
app.results.Value = a+b;
this is the error i got
'Value' must be a character vector or a string scalar.
Steven Lord
Steven Lord 2023년 6월 20일
It seems from the error message that your app.results field is an uieditfield with style equal to "text" whereas your app.val1 and app.val2 are uieditfields with style equal to "numeric". Either make your app.results have style "numeric" or convert the numeric result of a+b into a string before trying to assign it to the Value property of app.results.
n = 42 % numeric result
n = 42
s = string(n) % string result
s = "42"

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Title에 대해 자세히 알아보기

태그

제품


릴리스

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by