Change string words to number in table

조회 수: 5 (최근 30일)
Dion Theunissen
Dion Theunissen 2021년 10월 15일
답변: Chunru 2021년 10월 15일
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