How do I access sub-columns in table

I have a table which conisists of two variables with three columns each.
How do I access specific columns of this table (e.g. variable "I" column with 111 and variable "J" column with 555)
I want to keep a table with "I" and "J" as headings.
>> I= [1 2 3; 1 2 3;1 2 3];
>> J= [4 5 6;4 5 6;4 5 6];
>> K=table(I,J)
K = 3×2 table
I J
___________ ___________
1 2 3 4 5 6
1 2 3 4 5 6
1 2 3 4 5 6

回答(1 个)

Try this —
I = [1 2 3; 1 2 3;1 2 3];
J = [4 5 6;4 5 6;4 5 6];
K = table(I,J)
K = 3×2 table
I J ___________ ___________ 1 2 3 4 5 6 1 2 3 4 5 6 1 2 3 4 5 6
VN = K.Properties.VariableNames;
I1 = table(K.I(:,1), 'VariableNames',{VN{1}})
I1 = 3×1 table
I _ 1 1 1
J2 = table(K.J(:,2), 'VariableNames',{VN{2}})
J2 = 3×1 table
J _ 5 5 5
The variable names for the variables do not automatically extract as they would for indexing such as ‘K(:,1)’ (and parentheses indexing must always be last) so to keep them it is necessary to create new table arrays.
.

类别

帮助中心File Exchange 中查找有关 Color and Styling 的更多信息

产品

版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by