Programming Previous page   Next Page

Matrix Concatenation Functions

The following functions combine existing matrices to form a new matrix.

Concatenate matrices along the specified dimension
Horizontally concatenate matrices
Vertically concatenate matrices
Create a new matrix by replicating and tiling existing matrices
Create a block diagonal matrix from existing matrices


Here are some examples of how you can use these functions.

Concatenating Matrices and Arrays.   An alternative to using the [] operator for concatenation are the three functions cat, horzcat, and vertcat. With these functions, you can construct matrices (or multidimensional arrays) along a specified dimension. Either of the following commands accomplish the same task as the command C = [A; B] used in the section on Concatenating Matrices:

Replicating a Matrix.   Use the repmat function to create a matrix composed of copies of an existing matrix. When you enter

MATLAB replicates input matrix M v times vertically and h times horizontally. For example, to replicate existing matrix A into a new matrix B, use

Creating a Block Diagonal Matrix.   The blkdiag function combines matrices in a diagonal direction, creating what is called a block diagonal matrix. All other elements of the newly created matrix are set to zero:

Previous page  Concatenating Matrices Generating a Numeric Sequence Next page

© 1994-2005 The MathWorks, Inc.