concat two tables in matlab

You can use vertcat() function to vertically concatenate two tables if they have the same variable names.

Here's an example:

main.m
% create first table
T1 = table([1;2;3], {'A';'B';'C'}, 'VariableNames',{'Var1', 'Var2'});
% create second table
T2 = table([4;5;6], {'D';'E';'F'}, 'VariableNames',{'Var1', 'Var2'});
% concatenate two tables
T3 = vertcat(T1, T2);
230 chars
7 lines

In this example, T1 and T2 has the same variable names 'Var1' and 'Var2'. The resulting table T3 will have six rows and two variables.

Note that the horzcat() function can also be used to concatenates two tables side-by-side.

related categories

gistlibby LogSnag