Change string words to number in table

6 次查看(过去 30 天)
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?

采纳的回答

Chunru
Chunru 2021-10-15
% 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

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Characters and Strings 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by