combining two excel files. second excel file sub group of the first file.
2 次查看(过去 30 天)
显示 更早的评论
Hi. I have an excel file with 2000 rows and another excel file with 400 rows. I want to add the the second file to the first one at the row that have the matching names. please find example below. I would greatly appriciate the help.Thank you in advance!
tabel 1:
name category1 category 2 ....
112 yes no
888 no yes
986 yes yes
664 no no
table 2:
name result1 result2 .....
743 yes no
112 yes yes
664 no yes
note: the two tables have row name '112' and '664' in common. I want to add data to those row names! and leave the rows that dont match blank.
desired resulting tabel:
name category1 category 2.... result1 result2 ....
112 yes no yes yes
888 no yes
986 yes yes
664 no no no yes
0 个评论
采纳的回答
Jyotsna Talluri
2019-9-30
编辑:Jyotsna Talluri
2019-9-30
There can be many ways to do this.One possible way is ..
First join the two tables using 'outerjoin'
t=outerjoin(table1,table2,'Type','left','MergeKeys',true,'LeftKeys',{'name'},'RightKeys',{'name'});
It generates a new table with the columns of table2 appended to the colums of table1 with some NaN values for rows that don't match in the two tables. These NaN values can be replaced by empty values as below
v=t.Properties.VariableNames;
t=table2cell(t);
for i=2:size(t,2)
for j=1:size(t,1)
if isnan(t{j,i})
t{j,i}={[]};
end
end
end
t=cell2table(t,'VariableNames',v);
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spreadsheets 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!