MATLAB Answers

ALDO
0

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

ALDO
さんによって質問されました 2019 年 9 月 27 日
最新アクティビティ ALDO
さんによって コメントされました 2019 年 9 月 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 件のコメント

サインイン to comment.

1 件の回答

Answer by Jyotsna Talluri on 30 Sep 2019
Edited by Jyotsna Talluri on 30 Sep 2019
 Accepted Answer

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

  1 件のコメント

Thank you very much for your fast responce! I will try it out and let you know how it goes

サインイン to comment.



Translated by