Error using matlab.ui.control.EditField/set.Value 'Value' must be a character vector or a string scalar.
67 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Max-Henri Froger
le 24 Avr 2020
Commenté : Steven Lord
le 20 Juin 2023
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 commentaires
Réponse acceptée
Tommy
le 24 Avr 2020
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 commentaires
Shelynna Adjana Banawe
le 20 Juin 2023
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
le 20 Juin 2023
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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Startup and Shutdown dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!