How to combine table vertically

114 views (last 30 days)
I have two large tables I want to combine. They both have exactly the same column headings but different row numbers (>300) and the headings may be numbers, categoricals or text. I just want to combine them vertically so that the final table has just one column heading with all the data underneath.
  2 Comments
Wendy Cameron
Wendy Cameron on 24 Nov 2018
Thank you - this answer worked. I had been trying to use vertcat which works for an array and although one could convert the table to an arry as below, this solution here seems to work nicely in my situation. Thank you all very much or your ongoing assistance with Matlab.
Kind regards, Wendy

Sign in to comment.

Accepted Answer

madhan ravi
madhan ravi on 24 Nov 2018
Edited: madhan ravi on 24 Nov 2018

More Answers (1)

Peter Perkins
Peter Perkins on 27 Nov 2018
Wendy, I'm not sure you are getting the correct advice. You have said you want to vertically concatenate. outerjoin does not do that. It's a completely different operation, closer to horizontal concatenation.
If you do want to vertically concatenate, you do that the same way with tables as with anything else in MATLAB: [t1; t2]. No conversion needed. However, the variable names in the two tables do need to be the same. You have said, "They both have exactly the same column headings", so that should not be a problem. You also said, "the headings may be numbers, categoricals or text.", which doesn't make sense, so I think maybe you meant to say, "the variables in the table may be ...".
So, if you want to vertically concatenate, you shouldn't use outerjoin, and you don't need to convert back and forth with numeric.
  3 Comments
Wendy Cameron
Wendy Cameron on 27 Nov 2018
Great, thanks for the feedback Peter. It seems it worked just out of luck for my situation. I checked a few columns to be sure. But your method works too and is of course simpler and I have noted that down to use next time. Thanks once again for helping me to better understand matlab.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by