combining two excel files. second excel file sub group of the first file.

1 view (last 30 days)
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

Accepted Answer

Jyotsna Talluri
Jyotsna Talluri on 30 Sep 2019
Edited: Jyotsna Talluri on 30 Sep 2019
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);

More Answers (0)

Categories

Find more on Specifying Target for Graphics Output in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!