MATLAB
lecture 2
Olawale B. Akinwale
Dept of Electronic & Electrical
Engineering
Obafemi Awolowo University, Ile-Ife
History for MATLAB
• Fortran subroutines for solving linear (LINPACK)
and eigenvalue (EISPACK) problems
• Developed primarily by Cleve Moler in the 1970’s
• Later, when teaching courses in mathematics,
Moler wanted his students to be able to use
LINPACK and EISPACK without requiring
knowledge of Fortran
• MATLAB developed as an interactive system to
access LINPACK and EISPACK
History for MATLAB (cont’d)
• MATLAB gained popularity primarily through
word of mouth because it was not officially
distributed
• In the 1980’s, MATLAB was rewritten in C with
more functionality (such as plotting routines)
• The Mathworks, Inc. was created in 1984
• The Mathworks is now responsible for
development, sale, and support for MATLAB
• The Mathworks is an employer that hires co-ops
through our co-op program
Strengths of MATLAB
• MATLAB is relatively easy to learn
• MATLAB code is optimized to be relatively
quick when performing matrix operations
• MATLAB may behave like a calculator or as a
programming language
• MATLAB is interpreted, errors are easier to fix
• Although primarily procedural, MATLAB does
have some object-oriented elements
Weakness of MATLAB
• MATLAB is NOT a general purpose
programming language
• MATLAB is an interpreted language (making it
for the most part slower than a compiled
language such as C++)
• MATLAB is designed for scientific computation
and is not suitable for some things (such as
parsing text)
Workspace
• Allows access to data
• Area of memory managed through the
Command Window
• Shows Name, Size (in elements), Number of
Bytes and Type of Variable
Current Directory
• MATLAB functions can be called from any
directory.
• By default, MATLAB calls functions from a
number of directories located in the MATLAB
path.
• Your programs are only available if the current
directory is the one that they exist in or if that
directory has been added to the MATLAB
path.
Command History
• Shows a list of all commands which have
previously been used in the command
window.
• Allows access to the commands used during
this session, and possibly previous sessions
• Clicking and dragging to the Command
window allows you to re-execute previous
commands
Variables
• Types of variables include:
– Vector
– Matrix
– Structure
– Cell array
• There is no need to specify the type of a
variable when defining the variable.
Defining Variables
• A cell array is defined simply as
a = 5 or b = - 8
• An array (or a vector) can be defined as:
a = [1 2 3 4 5]; or a = [1,2,3,4,5]; or a = 1:1:5;
or a = 1:5;
Defining Variables (cont’d)
• Matrices are defined much like vectors,
except each row is delimited by a semicolon.
For example:
A = [ 1 2 3; 3 8 9; 2 9 3] gives
A=[123
389
2 9 3]
• Structures will be dealt with later in the course.
Matrix Manipulation
• Addition
• Multiplication
• Division
• Determinant
• Inverse
• Transpose / conjugate transpose
• Selecting an element, row or column