Array Functions and Colon Use in MATLAB

Array Functions and Colon Use in MATLAB

MATLAB provides some build-in function for Array handling.

Function Description
length(A) Returns the number of elements in Array A
size(A) Returns a row  vector [m,n]
where m and n are the size m*n of the Array A
reshape(A,m,n) Creates a m by n matrix from the elements of the matrix A
Where matrix A must have m*n elements
diag(V) Creates a square matrix with the elements of v in the diagonal, when V is vector
diag(A) Creates a vector from diagonal elements of A, where A is a matrix

Use of Colon:

A colon can be used to address a range of elements in a matrix or a vector

Matrix:

Colon Use Description
M(:,n) Refers to all elements in all rows of column n of Matrix M
M(n,:) Refers to all elements in all columns of row n of Matrix M
M(:,m:n) Refers to all elements in all rows between column m and n of Matrix M
M(m:n,:) Refers to all elements in all columns between rows m and n of Matrix M
M(m:n,p:q) Refers to all elements in rows from m to n and in columns from p to q of Matrix M

Vector:

Colon Use Description
V(:) Refers to all Elements of the vector V
V(m:n) Refers to all Elements of vectro V from m to n

Video Tutorial 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s