Change string words to number in table

5 Ansichten (letzte 30 Tage)
Dion Theunissen
Dion Theunissen am 15 Okt. 2021
Beantwortet: Chunru am 15 Okt. 2021
Hi,
I have a table where one column contains words like 'Clear', ' Clouds' and 'Rain'.
I want to replace those for values like 1,2 and 3.
Anyone who can help me with this?

Akzeptierte Antwort

Chunru
Chunru am 15 Okt. 2021
% Assume the column has the data
x.omst=["Clouds"; "Rain"; "Clear"]
x = struct with fields:
omst: [3×1 string]
% You can use the categorical data
x.omst = categorical(x.omst);
disp(x.omst)
Clouds Rain Clear
% Or numbers
x.omst = double(categorical(x.omst));
disp(x.omst)
2 3 1

Weitere Antworten (0)

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