Change string words to number in table

7 views (last 30 days)
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?

Accepted Answer

Chunru
Chunru on 15 Oct 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

More Answers (0)

Categories

Find more on Characters and Strings in Help Center and File Exchange

Products


Release

R2021b

Community Treasure Hunt

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

Start Hunting!