Main Content

horzcat

Concatenate multiple fi objects horizontally

Description

C = horzcat(A,B) concatenates B horizontally to the end of A when A and B have compatible sizes (the lengths of the dimensions match except in the second dimension).

C = horzcat(A1,A2,…An) concatenates A1,A2,…,An horizontally.

horzcat is equivalent to using square brackets for horizontally concatenating arrays. For example, [A,B] or [A B] is equal to horzcat(A,B) when A and B are compatible arrays.

Note

The fimath and numerictype properties of a concatenated matrix of fi objects, C, are taken from the leftmost fi object in the list A1,A2,…,An.

Input Arguments

collapse all

First input, specified as a scalar, vector, matrix, or multidimensional array.

Second input, specified as a scalar, vector, matrix, or multidimensional array.

The elements of B are concatenated to the end of the first input along the second dimension. The sizes of the input arguments must be compatible. For example, if the first input is a matrix of size 3-by-2, then B must have 3 rows.

List of inputs, specified as a comma-separated list of elements to concatenate in the order they are specified.

Any number of matrices can be concatenated within one pair of brackets. Multidimensional arrays are horizontally concatenated along the second dimension.

The inputs must have compatible sizes. For example, if A1 is a column vector of length m, then the remaining inputs must each have m rows to concatenate horizontally.

Tips

  • Horizontal and vertical concatenation can be combined together, as in [1 2;3 4].

  • The matrices in a concatenation expression can themselves be formed via a concatenation, as in [a b;[c d]].

  • [A B;C] is allowed if the number of rows of A equals the number of rows of B and if the number of columns of A plus the number of columns of B equals the number of columns of C.

  • When concatenating an empty array to a nonempty array, horzcat omits the empty array in the output. For example,

    horzcat(fi([1 2]),[])
    ans = 
    
         1     2
    
              DataTypeMode: Fixed-point: binary point scaling
                Signedness: Signed
                WordLength: 16
            FractionLength: 13

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

HDL Code Generation
Generate VHDL, Verilog and SystemVerilog code for FPGA and ASIC designs using HDL Coder™.

Version History

Introduced before R2006a

See Also