MATLAB Matrix - MATLAB

What is MATLAB Matrix?

A matrix is a two-dimensional array of numbers.

In MATLAB, you create a matrix by entering elements in every row as comma or space delimited numbers and using semicolons to mark the give up of each row.

For example, let us create a 4-by-5 matrix a –

MATLAB will execute the above statement and return the following result –

Referencing the Elements of a Matrix

To reference an element in the mth row and nth column, of a matrix mx, we write –

For example, to refer to the element in the 2nd row and 5th column, of the matrix a, as created in the last section, we type –

MATLAB will execute the above statement and return the following result –

To reference all the elements in the mth column we type A(:,m).

Let us create a column vector v, from the elements of the 4th row of the matrix a:

MATLAB will execute the above statement and return the following result –

You can also select the elements in the mth through nth columns, for this we write –

Let us create a smaller matrix taking the elements from the second and third columns –

MATLAB will execute the above statement and return the following result –

In the same way, you can create a sub-matrix taking a sub-part of a matrix.

MATLAB will execute the above statement and return the following result –

In the same way, you can create a sub-matrix taking a sub-part of a matrix.

For example, let us create a sub-matrix sa taking the inner subpart of a:

To do this, write –

MATLAB will execute the above statement and return the following result –

Deleting a Row or a Column in a Matrix

You can delete an entire row or column of a matrix through assigning an empty set of square braces [] to that row or column. basically, [] denotes an empty array.

For example, let us delete the fourth row of a –

MATLAB will execute the above statement and return the following result –

Next, let us delete the fifth column of a –

MATLAB will execute the above statement and return the following result –

Example

In this example, let us create a 3-by-3 matrix m, then we will copy the second and third rows of this matrix twice to create a 4-by-3 matrix.
Create a script file with the following code –

When you run the file, it displays the following result –

Matrix Operations

In this section, let us discuss the following basic and commonly used matrix operations −

  • Addition and Subtraction of Matrices
  • Division of Matrices
  • Scalar Operations of Matrices
  • Transpose of a Matrix
  • Concatenating Matrices
  • Matrix Multiplication
  • Determinant of a Matrix
  • Inverse of a Matrix

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

MATLAB Topics