table

Methods

Method Reference: table.vertcat

table: tbl = vertcat (tbl1, tbl2, …)

Vertical concatenation for tables.

tbl = vertcat (tbl1, tbl2, …) merges tables by vertically concatenating them, provided that all input tables have the same variable names but not necessarily in the same order. The positions of the variable names are matched to those of the first input table.

When any input table has row names, they must be unique across all input tables. In such a case, rows coming from input tables without row names are assigned default RowN names, where N is the row’s position in the output table. Output table’s Description and UserData properties are assigned using the first non-empty value.

Source Code: table

Example: 1

vertcat stacks tables on top of one another, appending rows. The tables must share the same variables (same names, compatible types). The [A; B] bracket syntax calls it for you.

 A = table (string ({'Li'; 'Diaz'}), [38; 40], categorical ({'M'; 'F'}), ...
            'VariableNames', {'Name', 'Age', 'Gender'})
A =
  2x3 table

     Name     Age    Gender    
    ______    ___    ______    

    "Li"       38         M    
    "Diaz"     40         F
 B = table (string ({'Brown'; 'Lee'}), [49; 30], categorical ({'M'; 'M'}), ...
            'VariableNames', {'Name', 'Age', 'Gender'})
B =
  2x3 table

     Name      Age    Gender    
    _______    ___    ______    

    "Brown"     49         M    
    "Lee"       30         M
 [A; B]
ans =
  4x3 table

     Name      Age    Gender    
    _______    ___    ______    

    "Li"        38         M    
    "Diaz"      40         F    
    "Brown"     49         M    
    "Lee"       30         M

Example: 2

Because vertical concatenation only adds rows, the column-aligned metadata is unchanged: a variable-scoped custom property carries straight through, and a table-scoped one is kept when the operands agree.

 A = table ([38; 40], categorical ({'M'; 'F'}), 'VariableNames', {'Age', 'Gender'})
A =
  2x2 table

    Age    Gender    
    ___    ______    

     38         M    
     40         F
 A = addprop (A, {'Study', 'Source'}, {'table', 'variable'});
 A.Properties.CustomProperties.Study = 'Cohort-7';
 A.Properties.CustomProperties.Source = {'intake', 'intake'};
 B = table ([49; 30], categorical ({'M'; 'M'}), 'VariableNames', {'Age', 'Gender'})
B =
  2x2 table

    Age    Gender    
    ___    ______    

     49         M    
     30         M
 B = addprop (B, {'Study', 'Source'}, {'table', 'variable'});
 B.Properties.CustomProperties.Study = 'Cohort-7';
 B.Properties.CustomProperties.Source = {'intake', 'intake'};
 V = [A; B];
 V.Properties.CustomProperties.Source
ans =
  1x2 cell array

    {'intake'}    {'intake'}
 V.Properties.CustomProperties.Study
ans = Cohort-7