Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

vertcat

Concatenate arrays vertically

Syntax

C = vertcat(A1,...,AN)

Description

C = vertcat(A1,...,AN) vertically concatenates arrays A1,...,AN. All arrays in the argument list must have the same number of columns.

  • If the inputs are multidimensional arrays, vertcat concatenates N-dimensional arrays along the first dimension. The remaining dimensions must match.

  • If the inputs are tables, vertcat concatenates by matching variable names. Variable names for all tables must be identical, except for order. Row names, when present, must be unique across tables.

    vertcat fills in default row names when some of the inputs have names and some do not. vertcat assigns values for each table property (except for RowNames) using the first nonempty value for the corresponding property in the tables A1,...,AN.

    If the inputs are timetables, then column names must be the same.

vertcat also concatenates character arrays. Each array being concatenated must have the same number of characters.

MATLAB® calls C = vertcat(A1, A2, ...) for the syntax C = [A1; A2; ...] when any of the inputs are an object.

Tips

To concatenate categorical arrays, see Combine Categorical Arrays.

If all the input arrays are ordinal categorical arrays, they must have the same sets of categories including their order. For more information, see Ordinal Categorical Arrays.

You can concatenate datetime arrays with cell arrays of character arrays.

You can concatenate duration arrays and calendar duration arrays. The result is a calendar duration array.

You can concatenate duration or calendar duration arrays with numeric arrays. Prior to concatenation, MATLAB converts the numeric array to an array of equivalent days using the days function.

You can concatenate string arrays with numeric arrays, logical arrays, character vectors, or cell arrays. The non-string arrays are first converted to a string array, and the output is returned as a string array.

For information on combining unlike integer types, integers with nonintegers, cell arrays with non-cell arrays, or empty matrices with other elements, see Valid Combinations of Unlike Classes.

Examples

collapse all

Create a 5-by-3 matrix, A.

A = magic(5);
A(:, 4:5) = []
A =

    17    24     1
    23     5     7
     4     6    13
    10    12    19
    11    18    25

Create a 3-by-3 matrix, B.

B = magic(3)*100
B =

   800   100   600
   300   500   700
   400   900   200

Vertically concatenate A and B.

C = vertcat(A,B)
C =

    17    24     1
    23     5     7
     4     6    13
    10    12    19
    11    18    25
   800   100   600
   300   500   700
   400   900   200

Create a table, A, with three rows and five variables.

A = table([5;6;5],['M';'M';'M'],[45;41;40],[45;32;34],{'NY';'CA';'MA'},...
    'VariableNames',{'Age' 'Gender' 'Height' 'Weight' 'Birthplace'},...
    'RowNames',{'Thomas' 'Gordon' 'Percy'})
A = 

              Age    Gender    Height    Weight    Birthplace
              ___    ______    ______    ______    __________

    Thomas    5      M         45        45        'NY'      
    Gordon    6      M         41        32        'CA'      
    Percy     5      M         40        34        'MA'      

Create a table, B, with the same variables as A except for order.

B = table(['F';'M';'F'],[6;6;5],{'AZ';'NH';'CO'},[31;42;33],[39;43;40],...
    'VariableNames',{'Gender' 'Age' 'Birthplace' 'Weight' 'Height'})
B = 

    Gender    Age    Birthplace    Weight    Height
    ______    ___    __________    ______    ______

    F         6      'AZ'          31        39    
    M         6      'NH'          42        43    
    F         5      'CO'          33        40    

Vertically concatenate tables A and B.

C = vertcat(A,B)
C = 

              Age    Gender    Height    Weight    Birthplace
              ___    ______    ______    ______    __________

    Thomas    5      M         45        45        'NY'      
    Gordon    6      M         41        32        'CA'      
    Percy     5      M         40        34        'MA'      
    Row4      6      F         39        31        'AZ'      
    Row5      6      M         43        42        'NH'      
    Row6      5      F         40        33        'CO'      

The variables of C are in the same order as the variables of A and default row names are used for the rows from B.

More About

collapse all

Tall Array Support

Tall arrays do not support vertical concatenation.

For more information, see Tall Arrays.

See Also

|

Introduced before R2006a

Was this topic helpful?