Change string words to number in table

5 visualizzazioni (ultimi 30 giorni)
Dion Theunissen
Dion Theunissen il 15 Ott 2021
Risposto: Chunru il 15 Ott 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?

Risposta accettata

Chunru
Chunru il 15 Ott 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

Più risposte (0)

Categorie

Scopri di più su Characters and Strings in Help Center e File Exchange

Prodotti


Release

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by