You are on page 1of 9

CL2014

MATLAB Programming
Lecture: 04

Course Instructor
Engr Muhammad Umar Khan Niazi
Office: C1-21, Ext.: 218, Email: umar.niazi@nu.edu.pk
1
2 Built-in Function to Generate Special Matrices

 Built-in functions are available to generate special matrices

 zeros(r,c)- makes matrix of r rows and c columns, all with zeros

 ones(r,c)- makes matrix of r rows and c columns, all with ones

 rand(r,c)- makes matrix of r rows and c columns, with random


numbers

 eye(n) - makes square matrix of n rows and columns. Main


diagonal (upper left to lower right) has ones, all other elements are
zero
3 Built-in Function to Generate Special Matrices
4 Built-in Function to Generate Special Matrices

 Built-in functions are available to generate special matrices

 find

Rot90 -Rotates matrix 90 degrees

Diag -Diagonal matrices and diagonals of matrix

Blkdiag -Constructs block diagonal matrix from


input arguments
5 Functions to Handle Matrices and Arrays
det() inv()

This give determinate of a matrix This give inverse of a matrix


6 Extracting a Sub Array
It is possible to extract a part of an array by using address of element
7 Replacing Part of Array
It is possible to extract a part of a 2D array by using address of element

Note:
: is use to select all
rows or columns
8 Replacing Part of Array
It is possible to replace a part of an array by using address of element
Command Return
a’ Transpose of a
find(a) Indices of all non-zero elements in a.
fliplr(a) Matrix a, flipped horizontally
flipud(a) Matrix a, flipped vertically.
inv(a) Inverse of a
min(a) Minimum-valued element of a. † † For a matrix, the
max(a) Maximum-valued element of a. † operation will be
carried
numel(a) The number of elements of a.
out separately on
repmat(a,m,n) A matrix where matrix a is repeated in m rows and n columns column.
each For a
reshape(a,m,n) Matrix a reshaped into m rows and n columns. vector (row or
column), the
size(a) The size of a (#rows, #columns, ...)
operation will be
sort(a) Vector a sorted into ascending order. † carried out on the
sum(a) Sum of elements of a. † vector.
unique(a) The list of unique elements of a in ascending order. 9

You might also like