Trying to change cells in a table

21 次查看(过去 30 天)
I have a small test table and I try to replace a column (or row) with the same size string. I just get NaN out of it. I would like to replace the table colum from (1,2,3,4,5) to type_1, type_2 etc. where the column names are in a 5x1 string. How can I do this? And how would it change for rows as well? Thanks

采纳的回答

Arif Hoq
Arif Hoq 2022-3-28
try this:
Column1Names={'type_1';'type_2';'type_3';'type_4';'type_5'};
% making another table
LastName = {'Sanchez';'Johnson';'Li';'Diaz';'Brown'};
Age = [38;43;38;40;49];
Height = [71;69;64;67;64];
Table2 = table(LastName,Age,Height)
Table2 = 5×3 table
LastName Age Height ___________ ___ ______ {'Sanchez'} 38 71 {'Johnson'} 43 69 {'Li' } 38 64 {'Diaz' } 40 67 {'Brown' } 49 64
Table2.LastName=Column1Names
Table2 = 5×3 table
LastName Age Height __________ ___ ______ {'type_1'} 38 71 {'type_2'} 43 69 {'type_3'} 38 64 {'type_4'} 40 67 {'type_5'} 49 64
Or
Table2(:,1)=Column1Names
Table2 = 5×3 table
LastName Age Height __________ ___ ______ {'type_1'} 38 71 {'type_2'} 43 69 {'type_3'} 38 64 {'type_4'} 40 67 {'type_5'} 49 64
  2 个评论
Arif Hoq
Arif Hoq 2022-3-30
my pleasure. @Dylan Clark if you find my answer helpful please mark it as an "Accepted answer"

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by