Introduction to Matlab | Matlab Tutorial – You can find the full Matlab tutorial here. In this lesson we will discuss the matrix in MATLAB.

Introduction

Matrices are fundamental elements of the MATLAB environment. The matrix is a two-dimensional matrix consisting of m rows and n columns. Special cases are column vectors (n = 1) and row vectors (m = 1).

This chapter explains how to apply various operations to matrices. The following topics will be discussed: Vectors and matrices in MATLAB, the inverse of matrices, determinants and matrix manipulation.

MATLAB supports two types of operations known as matrix operations and networks. First, matrix operations are discussed.

Matrix generation

Matrices are fundamental to MATLAB. Therefore, we need to become familiar with creating and manipulating matrices. Matrixes can be created in different ways

Vector input

A vector is a special case of a matrix. This section shows how to create vectors and matrices in MATLAB. As mentioned above, a table of dimension 1 × n is called a row vector and a table of dimension m × 1 is called a column vector. Vector elements in MATLAB are enclosed in square brackets and separated by spaces or commas. For example, to enter a string vector, v

>> v = [1 4 7 10 13]

v = 1 4 7 10 13

Column vectors are created in the same way, but a semicolon (;) should separate the components of the column vector,

>> w = [1;4;7;10;13]

w = 1

4

7

10

13

On the other hand, a row vector is converted into a column vector using the transposition operator. The conversion is indicated by an apostrophe or a single quotation mark ().

>> w = v

w = 1

4

7

10

13

Thus v(1) is the first element of the vector v, v(2) is the second element, and so on. In addition, we use the MATLAB colon notation (:) to access the element blocks. For example, to access the first three elements of v, one writes,

>> v(1:3)

Answer = 1 4 7

Or everything from the third to the last,

>> v(3, end)

Answer = 7 10 13

where the end means the last element of the vector. If v is a vector, then we write

>> v( 🙂

creates a column vector, while writing

>> v(1:end)

creates a vector of lines.

Matrix input

A matrix is an arrangement of numbers. To enter an array into MATLAB, you need to enter

– start with a hook, [

– individual elements on a line with spaces or commas (,)

– Use a semicolon (;) to separate lines

– the matrix ends with another hook, […].

Here’s a typical example. All the way to the z. B. Enter matrix A,

Come on in.

>> A = [1 2 3 ; 4 5 6 ; 7 8 9]

MATLAB then maps the 3 × 3 matrix as follows,

A = 1 2 3

4 5 6

7 8 9

Note that the use of semicolons (;) here differs from the above use to suppress output or write multiple commands on a single line.

Once we enter the matrix, it is automatically saved and noted in the workspace. We can just call this matrix A. We can then search for a particular element in the array by specifying its position. We write,

>> A(2,1)

Answer = 4

A(2,1) is the element in the second row and the first column. Its value is 4.

Indexing the matrix

We select matrix elements in the same way as for vectors, but now we need two indices. An element in row i and column j of matrix A is denoted by A(i,j). For example, in MATLAB, A(i,j) refers to the element Aij in the matrix A. The first index is the row number and the second index is the column number. For example, A(1,3) is an item in the first row and the third column. Here A(1,3)=3.

It is easy to correct a record thanks to indexing. Here we replace A(3,3)=9 by A(3,3)=0. Results.

>> A(3,3) = 0

A = 1 2 3

4 5 6

7 8 0

The individual elements of the matrix are treated as A(i,j), where i ≥ 1 and j ≥ 1. Zero or negative subscripts are not supported in MATLAB.

bowel operator

The Colon Operator will prove to be very helpful, and understanding how it works is essential to using MATLAB efficiently and comfortably. This can take many forms.

You often have to deal with matrices or vectors that are too large to fit into a single element. For example, suppose we want to introduce a vector x consisting of the points (0, 0.1, 0.2, 0.3, – – – – , 5). We can use the

>> x = 0:0.1:5 ;

The string vector consists of 51 elements

Line spacing

On the other hand, there is a command to create vectors with linear distances: lspace. It is similar to the gut operator (:), but gives direct control over the number of points. For example, for example..,

y = space (a,b)

forms a vector of the y-chain of 100 points, which are linearly distributed over each other and contain a and b.

y = space (a,b,n)

forms a vector of the y-chain of n points linearly spaced apart and including a and b. This is useful when we want to divide an interval into several sub-intervals of equal length. For example, for example..,

>> theta = linspace(0,2*ft,101)

divides the interval [0, 2π] into 100 equal sub-intervals and then produces a vector of 101 elements.

Colonel drive in matrix

The colon operator can also be used to select a specific row or column. Thus, the declaration A(m:n,k:l) specifies the rows from m to n and the columns from k to l. Index expressions refer to parts of the matrix. For example, for example..,

>> A(2, 🙂

Answer = 4 5 6

are the elements of the second line A.

The Colon Operator can also be used to extract a sub-matrix from the A-matrix.

>> A( :,2:3)

Answer = 2 3

5 6

8 0

A(:,2:3) is a submatrix with the last two columns of A.

A row or column of the matrix can be deleted by defining a zero vector, [ ].

>> A( :,2)=[]

Answer = 1 3

4 6

7 0

Creating a sub-matrix

To extract a sub-matrix B consisting of rows 2 and 3 and columns 1 and 2 of matrix A, proceed as follows

>> B = A([2 3], [1 2])

B = 4 5

7 8

To swap lines 1 and 2 A, use the line index vector with the colon operator.

>> C = A([2 1 3], 🙂

C = 4 5 6

1 2 3

7 8 0

It is important to note that the column operator (:) means all columns or all rows. To create a vector version of matrix A, proceed as follows

>> A( 🙂

Answer = 1

2

3

4

5

6

7

8

0

The submatrix consisting of the intersection of the rows p – q and the columns r – s is denoted by A(p:q,r:s).

In a particular case, a colon (:) as a row or column identifier terminates all entries in that row or column; thus

– A(:,j) is the jth column of A, while

– A(i,:) is the ith rule, and

– A(end, 🙂 selects the last line of A.

>> A

A = 1 2 3

4 5 6

7 8 9

>> A(2:3,2:3)

Answer = 5 6

8 9

>> A([1 3],[2 3])

Answer = 2 3

8 9

Delete row or column

To delete a row or column from a matrix, use the empty vector operator, [ ].

>> A(3, 🙂 = []

A = 1 2 3

4 5 6

The third row of matrix A is now deleted. To reconstruct the third rule, we use the matrix technique…

>> A = [A(1, :);A(2, :); [7 8 0].

A = 1 2 3

4 5 6

7 8 0

Matrix A is back in its original form.

Measurement

Use the Size command to define the dimensions of a matrix or vector. For example, for example..,

>> Size (A)

Answer = 3 3

means 3 rows and 3 columns.

Suite

If you cannot type the entire entry on one line, use consecutive points called ellipses … to indicate continuation, and then continue typing on the next line.

INTRODUCTION TO MATLAB

Note that spaces around the +, -, = characters are optional, but improve readability.

Matrix offset

The conversion is indicated by an apostrophe or a single quotation mark (). It returns the matrix around its main diagonal and transforms a row vector into a column vector. Like this,

>> A’

Answer = 1 4 7

2 5 8

3 6 0

In linear algebra notation, an m × n transpose of a real matrix A is an n × m matrix resulting from the alternation of the rows and columns of A. The transpose matrix is denoted by A^T.

Matrix generators

MATLAB provides functions that generate elementary matrices. The zero matrix, the unit matrix and the identity matrix are returned as a function of zeros, units and eyes, respectively.

INTRODUCTION TO MATLAB

For a complete list of elementary matrices and matrix manipulations, type almata help or doc almata. Here are a few examples:

1.

>> b= cube(3,1)

b = 1

1

1

Similarly, b can be defined as >> b=[1;1].

2.

>> Eye(3)

Answer = 1 0 0

0 1 0

0 0 1

Moreover, it is important to note that the three elementary operations of addition (+), subtraction (-) and multiplication (∗) also apply to matrices in all cases where the dimensions are compatible.

Two other important matrix generation functions are rand and randn, which generate matrices from (pseudo)random numbers using the same syntax as the eye.

In addition, matrices can be constructed in block form. With C defined by C = [1 2 ; 3 4], we can make the matrix D as follows.

>> D = [C zeros(2); uns(2) eyes(2)].

D = 1 2 0 0

3 4 0 0

1 1 1 0

1 1 0 1

Special moulds

MATLAB provides a number of special matrices (see Table 2.5). These matrices have interesting properties that make them useful for building examples and testing algorithms. For more information, see the MATLAB documentation.

Special matrices

Post Views : 0

 matlab tutorial for image processingmatlab programming basicsdesktop of matlabhow many windows are there in matlabmatlab array imatlab desktop toolsmatlab matrix operations pdfmatrix multiplication – matlab codecomplex conjugate transposematrix math on matlabmatlab create matrix of sizec 3 2 9 matlabmatlab onlinematlab tutorial youtubematlab programming bookmatlab program examplesimple matlab program to add two numbersmatlab arrays tutorialcolon in matlab arraycreate multidimensional array matlabmultidimensional array program in matlabmatlab fundamentals pdfmatlab user guidematlab bangla book pdfmatlab exercises and solutions pdfmatlab programming examples pdfmatlab commands with syntaxumich matlab tutoriallearn matlab in a daymatlab tutorial pdf for electrical engineersmatlab tutorial pdfmatlab tutorial for beginnersmatlab documentationmatlab tutorial pptbest matlab tutorial