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

조회 수: 1 (최근 30일)
ALDO
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

채택된 답변

Jyotsna Talluri
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);
  댓글 수: 1
ALDO
ALDO 2019년 9월 30일
Thank you very much for your fast responce! I will try it out and let you know how it goes

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Spreadsheets에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by