MATLAB: How to put two tables into one

join;mergetable

Hey,
This seems like a simple thing but I couldn't do it yet. How can I join two tables with the same column names? Example: Join the two first tables to become like the third one.

Best Answer

You can vertically concatenate them just as you would any other array:
Apple = [1 2 3]';
Banana = [4 5 6]';
T1 = table(Apple, Banana)
Apple = [9 8 7]';
Banana = [8 9 10]';
T2 = table(Apple, Banana)
T12 = [T1; T2]
Apple Banana
_____ ______
1 4
2 5
3 6
T2 =
Apple Banana
_____ ______
9 8
8 9
7 10
T12 =
Apple Banana
_____ ______
1 4
2 5
3 6
9 8
8 9
7 10
Related Question