horzcat - Concatenate arrays horizontally

Syntax

C = horzcat(A1, A2, ...)

Description

C = horzcat(A1, A2, ...) horizontally concatenates matrices A1, A2, and so on. All matrices in the argument list must have the same number of rows.

horzcat concatenates N-dimensional arrays along the second dimension. The first and remaining dimensions must match.

MATLAB calls C = horzcat(A1, A2,...) for the syntax C = [A1 A2 ...] when any of A1, A2, etc., is an object.

Examples

Create a 3-by-5 matrix, A, and a 3-by-3 matrix, B. Then horizontally concatenate A and B.

A = magic(5);            % Create 3-by-5 matrix, A
A(4:5,:) = []          

A =

    17    24     1     8    15
    23     5     7    14    16
     4     6    13    20    22


B = magic(3)*100       % Create 3-by-3 matrix, B

B =

   800   100   600
   300   500   700
   400   900   200


C = horzcat(A, B)      % Horizontally concatenate A and B

C =

    17    24     1     8    15   800   100   600
    23     5     7    14    16   300   500   700
     4     6    13    20    22   400   900   200

See Also

vertcat, cat, strcat, strvcat, special character []

  


 © 1984-2008- The MathWorks, Inc.    -   Site Help   -   Patents   -   Trademarks   -   Privacy Policy   -   Preventing Piracy   -   RSS