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

Respuestas (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.
.

Categorías

Más información sobre Color and Styling en Centro de ayuda y File Exchange.

Productos

Versión

R2022a

Preguntada:

el 20 de Jul. de 2023

Respondida:

el 20 de Jul. de 2023

Community Treasure Hunt

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

Start Hunting!

Translated by