Special Matrices

From ControlTheoryPro.com

Jump to: navigation, search
Symbol.gif
Special Matrices
Green carrot left.gif
All MATLAB Articles Matrix Operations
Green carrot.jpg
In order to prevent spam, users must register before they can edit or create articles.

1 Special Matrices

There are special matrices available in MATLAB. These matrices are often useful for initializing, comparisons, etc. (Note that initializing large variable before a loop allows the loop to execute much faster. See MATLAB Code Optimization for more details.)

1.1 Identity matrix

To create an identity matrix (ones along the diagonal and zeroes elsewhere) use the MATLAB command eye

 >> a = eye(3)
      a =
        1   0   0
        0   1   0
        0   0   1
 >> a = eye(3, 3)
      a =
        1   0   0
        0   1   0
        0   0   1

1.2 Ones Matrix

To create a matrix of all ones use the MATLAB command ones

 >> a = ones(2, 3)
      a =
        1     1     1
        1     1     1

1.3 Zero matrix

To create a matrix of zeros use the MATLAB command zeros

 >> a = zeros(2, 3)
      a =
        0     0     0
        0     0     0