Introduction
to MATLAB
What is MATLAB?
The
name MATLAB stands for matrix laboratory.
MATLAB
is a high performance language for technical computing. It integrates
computation, visualization, and programming in an easy to use environment where
problems and solutions are expressed in familiar mathematical notation. Typical
uses include:
·
Math
and computation
·
Algorithm
development
·
Modeling,
simulation and prototyping
·
Data
analysis, exploration and visualization
·
Scientific
and engineering graphics
·
Application
development, including graphical user interface building
MATLAB
is an interactive system whose basic data element is an array that does not
require dimensioning. This allows you to solve many technical computing
problems, especially those with matrix and vector formulations.
MATLAB
features a family of application specific solutions called toolboxes. Toolboxes are comprehensive collections of MATLAB
functions (M-files) that extend the MATLAB environment to solve particular
class of problems. The following is the list of toolboxes currently available
in MATLAB:
·
Communications
tool box
·
Signal
processing tool box
·
Image
processing tool box
·
Wavelet
tool box
·
Neural
network tool box
·
Data
acquisition tool box
·
Fuzzy
logic tool box
·
Control
systems tool box
·
Optimization
tool box
·
Spline
tool box
·
Statistics
tool box
·
Symbolic
math tool box
The
MATLAB system consists of five main parts:
The
MATLAB language. This is a high level matrix/array language with control flow
statements, functions, data structures, input-output, and object oriented
programming features.
The
MATLAB working environment. This is set of tools and facilities that you work
with as a Matlab user or programmer
Handle
Graphics. It includes high level commands for two-dimensional and three
dimensional data visualization, image processing, animation, and presentation
graphics
The
MATLAB mathematical function library. This is a vast collection of computation
algorithms ranging from elementary functions like sum, sine cosine to more
sophisticated functions like matrix inverse, fast fourier transforms.
The MATLAB Application Program Interface (API). This is a library that allows you to write C and fortran programs that interact with Matlab
Simulink, a companion program to
MATLAB, is an interactive system for simulating non-linear dynamic systems. It
is a graphical mouse driven program that allows you to model a system by
drawing a block diagram on the screen and manipulating it dynamically. It can
work with linear, nonlinear, continuous time, discrete time, multi rate and
hybrid systems.
Block
sets are add-ons to simulink that
provide additional libraries of blocks for specialized applications like
communications, signal processing, and power systems.
There
are both UNIX and PC (WINDOWS) versions of MATLAB, also available in PC version
is the STUDENT version of MATLAB.
MATLAB
can be accessed in the following ways:
·
In
the open access lab you can directly run MATLAB by going to
Start->Programs->Applications->Matlab6.0
(PC version)
·
On
a remote terminal follow this procedure
Start->Run->telnet
sunblast->login->on the prompt type “MATLAB”(UNIX version)
MATLAB
can be interactively used in two ways:
·
Directly
from the “command window”-Command window is the window which pops up when you
open MATLAB.
·
Programmed
by the creation of “M-files”-M-files are the text files made up of MATLAB
commands.
An
up to date list of hundreds of MATLAB related books is available at www.mathworks.com/books.
Many
resources for various branches of mathematics and science are at the education
specific web site www.mathworks.com/education.
For
getting started and using MATLAB go to http://www.mathworks.com/access/helpdesk/help/techdoc/matlab.shtml
Invoke MATLAB like any WINDOWS program. A text oriented command window will pop up, initially looking like:
To get started, type one of these commands: helpwin, helpdesk, or demo.
For information on all of the MathWorks products, type tour.
»
% This demo introduces to one of the basic matrix computational tool that is available in MATLAB.
% To enter a matrix, spaces are put between elements and semicolons are used to separate the rows.
% Brackets are placed around the data. For example to enter a 3-by-3 matrix A, type:
A = [1 2 3; 4 5 6; 7 8 0] % which results in :
A =
1 2 3
4 5 6
7 8 0
% We can run through some basic operations. For example our matrix A can be transposed with:
B = A’ % which results in :
B =
1 4 7
2 5 8
3 6 0
% The following code will create 41 points of a discrete-time sinusoid x(n) = sin(n);
index = 0:40; %vector of time indices
sine = sin(index);
stem(index,sine); % plot the sine function
Note that index(1) and sine (1) refer to n=0 in MATLAB. Try the changes to code with sine = sin(index/4) and sine = sin(index/2+1) and observe their effects.
The
demonstration actually tells you most of what you need to know MATLAB. Much of
the rest can be learned from the help command.
At the “»” prompt
type help to see a screen like:
» help
HELP topics:
matlab\general - General purpose commands.
matlab\ops - Operators and special characters.
matlab\lang - Programming language constructs.
matlab\elmat - Elementary matrices and matrix manipulation.
matlab\elfun - Elementary math functions.
matlab\specfun - Specialized math functions.
matlab\matfun - Matrix functions - numerical linear algebra.
matlab\datafun - Data analysis and Fourier transforms.
matlab\polyfun - Interpolation and polynomials.
matlab\funfun - Function functions and ODE solvers.
matlab\sparfun - Sparse matrices.
matlab\graph2d - Two dimensional graphs.
matlab\graph3d - Three dimensional graphs.
matlab\specgraph - Specialized graphs.
matlab\graphics - Handle Graphics.
matlab\uitools - Graphical user interface tools.
matlab\strfun - Character strings.
matlab\iofun - File input/output.
matlab\timefun - Time and dates.
matlab\datatypes - Data types and structures.
matlab\dde - Dynamic data exchange (DDE).
matlab\demos - Examples and demonstrations.
comm\comm - Communications Toolbox
comm\commsfun - Communications Toolbox SIMULINK S-functions.
comm\commsim - Communications Toolbox SIMULINK files.
wavelet\wavelet - Wavelet Toolbox.
wavelet\wavedemo - Wavelet Toolbox Demos.
fuzzy\fuzzy - Fuzzy Logic Toolbox.
fuzzy\fuzdemos - Fuzzy Logic Toolbox Demos.
fdident\fdident - Frequency Domain Identification Toolbox.
fdident\fddemos - Demonstrations for the FDIDENT Toolbox
toolbox\stats - Statistics Toolbox.
images\images - Image Processing Toolbox.
images\imdemos - Image Processing Toolbox --- demos and sample images
nnet\nnet - Neural Network Toolbox.
nnet\nndemos - Neural Network Demonstrations and Applications.
toolbox\signal - Signal Processing Toolbox.
toolbox\splines - Splines Toolbox.
toolbox\optim - Optimization Toolbox.
toolbox\ident - System Identification Toolbox.
toolbox\control - Control System Toolbox.
control\obsolete - (No table of contents file)
stateflow\stateflow - Stateflow
stateflow\sfdemos - (No table of contents file)
simulink\simulink - Simulink
simulink\blocks - Simulink block library.
simulink\simdemos - Simulink demonstrations and samples.
simulink\dee - Differential Equation Editor
toolbox\tour - An interface to Matlab demos, installed Toolboxes demos, and information
toolbox\local - Preferences.
For more help on directory/topic, type "help topic". »
This screen is really listing of directories in the MATLAB path, which is specified in pathdef.m in the matlab\toolbox\local directory. You can modify this path to create directories (like matlab\sankar in the above) to contain your own programs (M-files) which you can then call just like any other MATLAB function.
To obtain a listing and brief description of the commands in any of the directories mentioned, use help, followed by the directory name. Also use help, followed by any function name to get a description on it. For example
Example 1
» help sin
SIN Sine.
SIN(X) is the sine of the elements of X.
»
Example 2
» help filter
FILTER One-dimensional digital filter.
Y = FILTER(B,A,X) filters the data in vector X with the
filter described by vectors A and B to create the filtered
data Y. The filter is a
"Direct Form II Transposed"
implementation of the standard difference equation:
a(1)*y(n) = b(1)*x(n) + b(2)*x(n-1) + ... + b(nb+1)*x(n-nb)
- a(2)*y(n-1) - ... - a(na+1)*y(n-na)
If a(1) is not equal to 1, FILTER normalizes the filter
coefficients by a(1).
When X is a matrix, FILTER operates on the columns of X. When X
is an N-D array, FILTER operates along the first non-singleton
dimension.
[Y,Zf] = FILTER(B,A,X,Zi) gives access to initial and final
conditions, Zi and Zf, of the delays. Zi is a vector of length
MAX(LENGTH(A),LENGTH(B))-1 or an array of such vectors, one for
each column of X.
FILTER(B,A,X,[],DIM) or FILTER(B,A,X,Zi,DIM) operates along the
dimension DIM.
See also FILTER2, FILTFILT (in the Signal Processing Toolbox).
»
The same kind of information can be accessed graphically by using helpwin command. A more detailed documentation is available in HTML format using helpdesk if you have a web browser and have installed all of the help files.
To exit MATLAB, type exit or quit, or use the file menu, as with most Windows applications.