How to join 2 MATLAB tables based on similarity in values of first column?
6 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Guillaume
2018-11-22
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')
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!