Reading Text File in Matlab as Matrix Interactive

If y'all always tried to work with huge matrices, you will know how unpleasant and boring. Here is where Matlab come to play, it makes working with Matrices easier.

With Matlab, one of the major trouble for beginners is to understand how the software works and what the software need in order to help them achieve their goal using it.

In this read, we volition hand over to you some basic Matlab Matrix operation and how to apply them to become what y'all want.

Content:

Write a Matrix in Matlab
Find the size of a Matrix
Add Matrices
Divide Matrices element by element
Find the inverse of a Matrix
Find the determinant of a Matrix
Ascertain a Matrix with Random elements
Find the diagonal of a Matrix
Compute the Transpose of a Matrix
Extract an element in a Matrix
Multiply Matrices
Multiply two Matrices chemical element by element
Create a Matrix with all elements equal to zero
Create a Matrix with All elements equal to one

Matlab Matrix Operations

Write a Matrix in Matlab

matlab-matrix-operations

we volition write

A=[ane i -2;2 two 1;2 one 1]

after pressing ENTER, here is how it will await in Matlab window

matlab-matrix-operations
Notice the size of a Matrix

The size of a Matrix is its number of rows and columns. To find the size of a Matrix, utilise the following lawmaking

size(A)

Notation A here is the matrix we created in the previous step.

Here is its size

matlab-matrix-operations

Pregnant, A has iii rows and 3 columns.

Let's effort a second case.

matlab-matrix-operations

If nosotros type

size(B)

Nosotros volition run into the post-obit

matlab-matrix-operations
Add together Matrices

To add together 2 matrices A and B, we demand size(A) to be identical to size(B)

Then, let's create a new Matrix C with the same size as A

matlab-matrix-operations

Now we can add A and C using the post-obit code

A+C

matlab-matrix-operations
Divide Matrices element by element

To separate two Matrices element past chemical element use the post-obit

A./C

Remember both matrices demand to have the same size.

matlab-matrix-operations
Find the inverse of a Matrix

matlab-matrix-operations

To observe the inverse of a Matrix, apply the lawmaking:

inv(A)

matlab-matrix-operations
Find the determinant of a Matrix

To discover the determinant of a Matrix in Matlab, apply the following code

det(A)

matlab-matrix-operations
Define a Matrix with Random elements

To create a Matrix with Random chemical element in Matlab, utilise

rand(3,2)

Where (3,2) is the size of the Matrix

Find the diagonal of a Matrix

DIAG assistance admission diagonals of Matrices in Matlab.

To find the main diagonal of A, we volition utilize

diag(A)

to observe the starting time upper diagonal use

diag(A,1)

to find the first lower diagonal use

diag(A,-1)

Here is how Matlab read matrix diagonals

matlab-matrix-operations

Compute the Transpose of a Matrix

To find the transpose of a Matrix, use the following

A'

or

transpose(A)

Here is the transpose of A

matlab-matrix-operations

Extract an element in a Matrix

Y'all can individually access element of a Matrix or a whole vector.

Let'due south consider the following Matrix

matlab-matrix-operations

If I need to admission the first row of the Matrix, I will apply the following code

C(1,:)

I volition use the following to access the element on the first rows-2nd column.

C(ane,2)

The post-obit volition help admission element of the 3rd column

C(:,three)

Multiply Matrices

To multiply A X B, A and B being ii distinct matrices, A and B has to obey these weather.

To multiply A past B in Matlab, use the code

A*B

Multiply 2 Matrices chemical element by element

To multiply a Matrices element by element, recollect the size of the 2 matrices has to exist the same.

Use the following line

A.*B

Create a Matrix with all elements equal to zero

matlab-matrix-operations

To create a Matrix with all elements equal to zero, use the post-obit code

G=zeros(iii,4)

where (3,iv) is the size of the Matrix

Create a Matrix with All elements equal to i

matlab-matrix-operations

To create a Matrix with all elements equal to 1, utilize the post-obit code

O=ones(iv,5)

where (4,5) is the size of the Matrix

Summary of Matrix functions

size: Size of a matrix

det: Determinant of a square matrix

inv: Inverse of a matrix

rank: Rank of a matrix

rref: Reduced row echelon form

eig: Eigenvalues

poly: Feature polynomial

norm: Norm of matrix

lu: LU factorization

svd: Singular value decomposition

eye: Identity matrix

zeros: Matrix of zeros

ones: Matrix of ones

diag: extract/create diagonal of a matrix

rand: randomly generated matrix

crandallcappasay.blogspot.com

Source: https://tutorial45.com/matlab-matrix-operations/

0 Response to "Reading Text File in Matlab as Matrix Interactive"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel