Compare two excel files and generate a new one that contains all columns
조회 수: 8 (최근 30일)
이전 댓글 표시
Hello everyone,
I have two excel files. They are filled out with numbers and text. The first file has 6 columns, say (a, b, c, d, e, f), while the second file has one column called "g" in addition to some similar columns like (a, b, c) , i.e, second files has 4 columns (a, b, c, g).
I would like to go through each row of the second file, figure out it is equivalent with which row of the first file (which row in the first file has the same values in columns (a, b, c)), and then add the value in column "g" to the first file and generate a new excel with 7 columns (a,b,c,d,e,f,g).
Any input would be greatly appreciated! Thanks!
댓글 수: 2
dpb
2020년 5월 6일
By any chance are the columns named and are the names consistent between workbooks? That would be the simplest and most convenient. If not and have to match data, then it gets a little more complex if aren't all numeric or text.
Perhaps attaching a couple of small sample files to illustrate the content would be easiest for folks to work with rather than just taking a stab at it...
채택된 답변
Cris LaPierre
2020년 5월 7일
편집: Cris LaPierre
2020년 5월 7일
Sounds like you want to join tables using a,b, and c as your key variables. I would use readtable to import the two spreadsheets into MATLAB (or the import tool) as tables, and then use the interactive Join Tables task in a live script to generate the correct output.
댓글 수: 6
Cris LaPierre
2020년 5월 7일
편집: Cris LaPierre
2020년 5월 8일
It runs quickly for me. You have about 2000 extra rows of data in this file (delimited, but no entries). Perhaps it is struggling with that? Try removing various lines to see if you can identify which one is causing the problem.
The only real options are the 1st, 4th and 6th. You might not need the 4th anyway. The last line just gets rid of the extra rows added to the table.
추가 답변 (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!