Select columns from a table and add them into another table
48 ビュー (過去 30 日間)
古いコメントを表示
Hey all,
I have C1 and C2. Each one is (1 x 2) means that containing 2 tables inside. I want to copy column numbers 5, 6, and 8 from all tables in C1 to the exact table in C2 (after the first column of C2 and before other columns).
I think I should use vertcat and then use groupsummary but unfortunately don't know how to do that.
As my C1 and C2 have a very large size I just cut part of them and attached them, original C1 and C2 are 1 x 85.
% This is not a code but I want something like this
%copy C1{1, 1}.column5,column6,column8
%paste to C2{1, 1}>>> in front of first existing column
%copy C1{1, 2}.column5,column6,column8
%paste to C2{1, 2}>>> in front of first existing column
Any advice is truly helpful
Thank you so much
Best regards
0 件のコメント
採用された回答
fred ssemwogerere
2020 年 2 月 8 日
Hello, you don't need to use "groupsummary" or "vertcat" for this. Instead use; "addvars". I think this should do nicely:
% Taking "C2" to be the cell with tables you are copying into, using data from tables in cell "C1"
for i=1:size(C2,1)
for j=1:size(C2,2)
% Replace "Var5", "Var6", and "Var8" with names of your table column variables in cell "C1" at positions: 5,6,and 8 as you mentioned
C2{i,j}=addvars(C2{i,j},C1{i,j}.Var5,C1{i,j}.Var6,C1{i,j}.Var8,'Before',2);
% "2" specifies to insert the data after the first column
end
end
3 件のコメント
fred ssemwogerere
2020 年 2 月 8 日
Hello, all that is not required, just make this small edit to the code above on line 3 (I have added a field: "NewVariableNames"). Change the input arguments; "Var5","Var6", "Var8", according to the names you want to use
% Taking "C2" to be the cell with tables you are copying into, using data from tables in cell "C1"
for i=1:size(C2,1)
for j=1:size(C2,2)
% Replace "Var5", "Var6", and "Var8" with names of your table column variables in cell "C1" at positions: 5,6,and 8 as you mentioned
C2{i,j}=addvars(C2{i,j},C1{i,j}.Var5,C1{i,j}.Var6,C1{i,j}.Var8,'Before',2,'NewVariableNames',{'Var5','Var6','Var8'});
% "2" specifies to insert the data after the first column
end
end
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Logical についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!