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)
VN = K.Properties.VariableNames;
I1 = table(K.I(:,1), 'VariableNames',{VN{1}})
J2 = table(K.J(:,2), 'VariableNames',{VN{2}})
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 についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!