Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Introduction MATLAB
MATLAB - Overview
MATLAB (matrix laboratory) is a fourth-generation
high-level programming language and interactive
environment for numerical computation, visualization
and programming.
Objectives used in MATLAB
• It allows matrix manipulations.
• plotting of functions and data
• implementation of algorithms.
• creation of user interfaces.
• interfacing with programs written in other
languages, including C, C++, Java, and FORTRAN .
• analyze data.
• developed algorithms.
Applications of MATLAB
• MATLAB is widely used as a computational tool in
science and engineering fields of physics,
chemistry, math and all engineering streams. It is
used in a range of applications including:
• Signal Processing and Communications
Image and Video Processing
Control Systems
Test and Measurement
Computational Finance
Basic syntax of MATLAB
• MATLAB environment behaves like a super-
complex calculator. You can enter commands at
the >> command prompt.
MATLAB is an interpreted environment. In other
words, you give a command and MATLAB
executes it right away.
Type a valid expression, for example,
5+5
And press ENTER
• ans = 10
Let us take up few more examples
• 3 ^ 2 % 3 raised to the power of 2
• ans = 9
• sin(pi /2) % sine of angle 90
• When you click the Execute button, or type Ctrl+E,
MATLAB executes it immediately and the result.
• ans = 1
• 7/0 % Divide by zero
• ans = Inf warning: division by zero
Use of Semicolon (;) in MATLAB
• Semicolon (;) indicates end of statement. However,
if you want to suppress and hide the MATLAB
output for an expression, add a semicolon after the
expression.
• x = 3; y = x + 5
y=8
• The percent symbol (%) is used for indicating a comment
line. For example,
x = 9 % assign the value 9 to x
Special Variables and Constants
• MATLAB supports the following special variables
and constants:
1.InfInfinity.NaNUndefined numerical result (not a number).
piThe number π.
Naming Variables
Variable names consist of a letter followed by any
number of letters, digits or underscore.
MATLAB is case-sensitive.
Variables must have values before they are used.
Saving Your Work
• The save command is used for saving all the
variables in the workspace, as a file with .mat
extension, in the current directory.
Creating Vectors
• A vector is a one-dimensional array of numbers.
MATLAB allows creating two types of vectors:
Row vectors.
Column vectors.
Row vectors are created by enclosing the set of
elements in square brackets, using space or
comma to limit the elements.
Examples of raw vector
Ex:r = [7 8 9 10 11]
MATLAB will execute the above statement result is:
r=7 8 9 10 11.
r = [7 8 9 10 11]; t = [2, 3, 4, 5, 6]; res = r + t
after MATLAB execution result will be
res = 9 11 13 15 17
Column Vector
Column vectors: are created by enclosing the set of
elements in square brackets, using semicolon(;) to limit the
elements.
Ex.c = [7; 8; 9; 10; 11]
After executing MATLAB the result will be
C= 7
8
9
10
11
Referencing the Elements of a vector
• You can be reference one or more of the elements
of a vector in several ways.
The ith component of a vector v is referred as v(i)
Ex1: v=[1;2;3;4;5;6;];
v(3)
After execution ans=3
Ex2: v=[1;2;3;4;5;6;];
V(:)
It will display all the elements in column.
MATLAB MATRIX
• A matrix is a two-dimensional array of numbers.
• In MATLAB, a matrix is created by entering each row as
a sequence of space or comma separated elements,
and using semicolons to mark the end of each row.
• For example, let us create a 3-by-3 matrix as:
• m = [1 2 3; 4 5 6; 7 8 9]
• M= 1 2 3
4 5 6
• 7 8 9
multi-dimensional arrays:
• it is possible in MATLAB to handle multi-
dimensional arrays.
• MATLAB's internal data structure is limited to a
two-dimensional matrix.
• But to handle multi-dimensional arrays in
MATLAB, you can create your own functions in
MATLAB language.
What is Simulink in matlab?
• Simulink is an add-on product to MATLAB, it
provides an interactive, simulating, graphical
environment for modeling and analyzing of
dynamic systems.
MATLAB consists of five main parts
1.MatLab Language
2.MatLab working environment
3.Handle Graphics
4.MatLab function library
5.MatLab Application Program Interface (API)