0% found this document useful (0 votes)
8 views

Lab 1

MATLAB is a programming environment used for matrix manipulation, plotting of data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages. It allows matrix and array operations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages. MATLAB is case sensitive and uses comment symbols like % and semicolons ; to suppress output. Common operations include addition, subtraction, multiplication, and transposition of matrices using syntax like +, -, *, and '. MATLAB also allows accessing and manipulation of matrix elements using indexing, colon operators : , and functions like ones, zeros, eye and deletion of entries.

Uploaded by

Mashood Ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Lab 1

MATLAB is a programming environment used for matrix manipulation, plotting of data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages. It allows matrix and array operations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs written in other languages. MATLAB is case sensitive and uses comment symbols like % and semicolons ; to suppress output. Common operations include addition, subtraction, multiplication, and transposition of matrices using syntax like +, -, *, and '. MATLAB also allows accessing and manipulation of matrix elements using indexing, colon operators : , and functions like ones, zeros, eye and deletion of entries.

Uploaded by

Mashood Ahmad
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

MATLAB

INTRODUCTION

Used frequently to see the effect of commands All used variables


are saved here along
with their dimensions
Opens editor window (m-file)

Keeps record
of previously
used commands
Figure Window
Commands
• save

• clc

• clear

• help
Important Points
• MATLAB is case sensitive.

• For comment: %.

• ‘;’ at end to suppress the display of result.

• CTRL+C interrupts MATLAB execution.


VECTORS,ARRAYS & MATRICES
 Matrix (size m x n, m=rows, n=columns)
Doesn’t display
result on
command window

 Vectors :Row vector, Column vector


 Row vector (m=1, single row)
 Column vector (n=1, single column)
 Array : General category
 Matrix, vectors and scalars, all are
arrays.
 Scalar is special case of array. The
size is 1 x 1.
MATRIX OPERATIONS

Operation Syntax in MATLAB Effect


Addition + Adds two arrays element wise
Subtraction - Subtracts element wise
Multiplication * Scalar or Array multiplication
(Compatibility: m x n * n x p = m x p)
Power or ^ A ^ n multiplies A ‘n’ times.
Exponent A^2 means A*A (matrix multiplication)
Transpose ‘ Changes rows into columns
Left division \ x=M\b is solution to M*x=b
Right division / Divide all entities of array by a scalar
DOT OPERATOR (.)

Operation Syntax in MATLAB Effect


Multiplication * Scalar or Array multiplication
(Compatibility: m x n * n x p = m x p)
.* Element by element multiplication
Power or ^ A ^ n multiplies A ‘n’ times.
Exponent A^2 means A*A (matrix multiplication)
.^ Raises power to each element of matrix
CONCATENATION
 Two types of concatenation

 Concatenating a row
 Number of columns in both
must be same

 Concatenating a column
 Number of rows in both must
be same
COLON OPERATOR (:)
 Two types of formats used
 Starting value : Ending value
 e.g. j:k => [j j+1 j+2 … k]
 Starting value: Step size: Ending value
 e.g. j:s:k => [j j+s j+2s … k]
 If step size is not entered, it is ‘1’ by default
as in the first format.
ACCESSING MATRIX ENTITIES
 Accessing a certain row => A(m1,:)
 ‘m1’ => select a certain row
 ‘:’ =>select all columns

 Accessing a certain column => A(:,n1)


 ‘n1’ => select a certain column
 ‘:’ => select all rows
ACCESSING MATRIX ENTITIES
 Accessing a certain rectangular or square
portion of a matrix => A(m1:m2,n1:n2)
 ‘m1:m2’ => select certain rows
 ‘n1:n2’ => select certain columns

 Accessing only a single element => A(m1,n1)

 Accessing WHOLE MATRIX => A(:,:)


INDEXING OF ARRAYS IN MATLAB
 Indexing needs to be understood if one
wants to access elements of array.
1 4 7
 Accessing elements of Matrix 2 5 8
1. Detailed method in previous slide 3 6 9
2. Elements are numbered from 1 up
till the last element
 Accessing elements of vector
 Elements are numbered from 1 up
till the last element only
Indexing done in red numbering in visuals

1 2 3 4 5 6 7 8 9 10
DELETING ENTRIES
 There are two methods of deleting entries
from a matrix
1 4 7
 Indicating rows and columns 2 5 8
1. Similar like accessing entities (see 3 6 9
lecture 1)
2. Syntaxes: A(m1,:)=[], A(:,n1)=[].
 Using indexes
 A(j:s:k)=[]; The remaining entities
are reshaped into a row vector.
Remember: A(m1,n1)=[] will result in an
error since the result is not a matrix
anymore.
SPECIAL VARIABLES
 ans : The default variable used for the most recent result. This variable is
also used as a default variable to store any value.

 pi : It has the value of 3.14 .

 eps : The smallest number such that when added to 1 creates a number
greater than 1

 inf : Stands for infinity (1/0)

 ‘i’ or ‘j’ : I or j =
OTHER USEFUL COMMANDS
TRY YOURSELF

ones (m,n) zeros (m,n) eye(m) cos sin


ceil exp floor angle acos
asin log log10 log2 real
atan conj sqrt tan sinc
abs imag round sign sum

You might also like