Error using matlab.ui.control.EditField/set.Value 'Value' must be a character vector or a string scalar.
67 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Max-Henri Froger
il 24 Apr 2020
Commentato: Steven Lord
il 20 Giu 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 Commenti
Risposta accettata
Tommy
il 24 Apr 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 Commenti
Shelynna Adjana Banawe
il 20 Giu 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
il 20 Giu 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
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Startup and Shutdown in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!