필터 지우기
필터 지우기

Replacing numerical values in table with string

조회 수: 6 (최근 30일)
Emu
Emu 2024년 3월 22일
편집: Stephen23 2024년 3월 22일
I have a column of numerical data (all 2 digit) which I want to replace with a string.
This is my code which doesn't work. I would like the data to read e.g. 'voc_15'.
for b=1:size(type_data_table,1)
type_data_table.voc_type(b) = ['voc_', num2str(type_data_table{b, 'voc_type'})];
end

답변 (1개)

Stephen23
Stephen23 2024년 3월 22일
편집: Stephen23 2024년 3월 22일
This is MATLAB, so forget about using a loop like that. Either replace the entire column at once or use e.g.:
For example:
T = array2table(randi(99,7,3))
T = 7x3 table
Var1 Var2 Var3 ____ ____ ____ 2 32 52 69 60 82 70 4 70 70 30 3 45 43 62 3 99 36 55 16 75
T.Var2 = "voc_"+T.Var2
T = 7x3 table
Var1 Var2 Var3 ____ ________ ____ 2 "voc_32" 52 69 "voc_60" 82 70 "voc_4" 70 70 "voc_30" 3 45 "voc_43" 62 3 "voc_99" 36 55 "voc_16" 75

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품


릴리스

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by