Compare two excel files and generate a new one that contains all columns
3 views (last 30 days)
Show older comments
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
dpb
on 6 May 2020
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...
Accepted Answer
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
Cris LaPierre
on 7 May 2020
Edited: Cris LaPierre
on 8 May 2020
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.
More Answers (0)
See Also
Categories
Find more on Spreadsheets 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!