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개)

Star Strider
Star Strider 2023년 7월 20일

0 개 추천

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

질문:

2023년 7월 20일

답변:

2023년 7월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by