How to join 2 MATLAB tables based on similarity in values of first column?

13 views (last 30 days)
I have 2 MATLAB tables, suppose A and B. A and B are of different dimensions Eg. A has dimensions 53000x67 and B has dimensions 61000 x 388. The first column of both tables A and B consists of a DateTime datatype timestamp Eg. 2018-01-01 12:00:00 and so on. Not all timestamps of both tables are same, as is clear from the different dimensions. I want to create a new table C, which has all the columns of table A and table B together whenever the timestamp (first columns of tables A and B) are the same.
Eg. Table A has data
TimeStamp Column1 Column2 ...... Column 67
Row 1
Row 2
...
Row 53000
Eg. Table B has data
TimeStamp Column1 Column2 ...... Column 388
Row 1
Row 2
...
Row 61000
I would like to create the table C which has
TimeStamp Column1 Column2 ...... Column 453 (387 columns of B + 66 of A)
Row 1
Row 2
...
Row x (n number of rows which may be created during similar TimeStamp)
I tried using join() and giving Keys as the first column name but it didn't work. I have looked into Mathworks Community and used outerjoin() and other similar methods, but they aren't working in the present perspective. Basically, the purpose is to join the 2 tables together against the similar timestamps. Any help in this regard will be highly appreciated. Thanks

Accepted Answer

Guillaume
Guillaume on 22 Nov 2018
Your description is that of an innerjoin, not an outerjoin. It's unclear why any one of the join wouldn't work. You must be doing something wrong but you don't tell us what you did precisely.
innerjoin(A, B, 'Keys', 1)
However, I would recommend converting your tables to timetables, Then you can use synchronize instead.
synchronize(table2timetable(A), table2timetable(B), 'intersection')

More Answers (0)

Categories

Find more on Tables 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!