Is it possible to join tables with different variables and sizes by filling/padding the missing variables and rows with NaN or similar?

14 views (last 30 days)
I have 4 tables that I woulk like to merge/join together into 1 large table. The 4 tables have mostly the same variables, but also a few unique ones for each table. They are also of differing sizes.
Is there a way to join/merge them by padding each table with the missing variables and rows (with NaN or 999 or something like that) so that they are able to be joined?
I've attached a few small subsets of the 4 tables in a .mat file.
  4 Comments

Sign in to comment.

Answers (1)

John Navarro
John Navarro on 10 Jun 2020
Edited: John Navarro on 10 Jun 2020
C = outerjoin(A,B,'Keys',{'Common Variable'},'MergeKeys',true)
% Where A and B are the corresponding Tables to merge.
Then you conbine C with the following Table. And so on.
In other words, you take two tables and make one of them. Next, you repeat the process until you became all your Tables in one.
BUT, It wont work if you use the automatic code that is generated by the Task option in the live script.
C = outerjoin(A,B,'Type','left','Keys',{'Country'},'MergeKeys',true)

Products


Release

R2017b

Community Treasure Hunt

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

Start Hunting!