I am trying to take the user input and put it in a vector I tried this following code but this is what I get :Unable to resolve the name handles.Va​leurdeXEdi​tField.Str​ing.

1 Ansicht (letzte 30 Tage)
% Button pushed function: CalculerButton
function CalculerButtonPushed(app, event)
s = handles.ValeurdeXEditField.String;
try
d = str2double(strsplit(s{:}, ','));
catch
error('Edit field must contain comma separated values such as "6, 5, 3.14"')
end
end
end

Antworten (1)

Voss
Voss am 17 Mai 2022
Maybe handles should be app?
  2 Kommentare
Oumaima Bendidi
Oumaima Bendidi am 18 Mai 2022
function CalculerButtonPushed(app, event)
x=app.ValeurdeXEditField.Value;
try
d = str2double(strsplit(x{:}, ' '));
app.fXEditField.Value=z;
catch
error('Edit field must contain space separated values such as "30 40 50"')
end
i tried this code but i still cant get the values into a vector. my question are probably dumb sorry :((
Voss
Voss am 18 Mai 2022
If you want to get an array of numbers from an EditField, try this:
x = str2num(app.ValeurdeXEditField.Value);
(You don't need to try to parse the array yourself, e.g., by using strsplit. In fact, the lines you have with strsplit will always throw an error when you try to do x{:} or s{:} because x and s are not cell arrays.)
If you want to get a single scalar number from a NumericEditField, try this:
x = app.ValeurdeXEditField.Value;

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Produkte


Version

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by