Error using matlab.ui.control.EditField/set.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
댓글 수: 0
채택된 답변
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
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
Error using matlab.ui.control.EditField/set.Value
'Value' must be a character vector or a string scalar.
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
s = string(n) % string result
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Title에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!