Compare two excel files and generate a new one that contains all columns

20 views (last 30 days)
Susan
Susan on 6 May 2020
Edited: Cris LaPierre on 8 May 2020
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 Comments
Susan
Susan on 7 May 2020
Thanks for your reply. Yes, the columns are named and the names consist between workbooks. I have attached 2 files to illustrate the content.
1st file has several columns, among those 3 of them are common between 2 files. The second file has only 4 columns and I would like to add the 4th column to the first file accordingly.
There is a chance that in one row, we cannot match the data in 3 coulmns of two files and I would like to figure out in which row it may happen.
Any help would be greatly appreciated. Thanks!

Sign in to comment.

Accepted Answer

Cris LaPierre
Cris LaPierre on 7 May 2020
Edited: Cris LaPierre on 7 May 2020
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 Comments

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!