SlideShare ist ein Scribd-Unternehmen logo
1 von 94
11
Introduction to MATLAB
RAJASTHAN
2
Topics..
 What is MATLAB ??
 Basic Matrix Operations
 Script Files and M-files
 Some more Operations and Functions
APPLICATIONS:
 Plotting functions ..
 Image Processing Basics ..
 Robotics Applications ..
3
Topics..
 What is MATLAB ??
 Basic Matrix Operations
 Script Files and M-files
 Some more Operations and Functions
APPLICATIONS:
 Plotting functions ..
 Image Processing Basics ..
 Robotics Applications ..
4
MATLAB
 MATLAB is a program for doing numerical
computation. It was originally designed for solving
linear algebra type problems using matrices. It’s
name is derived from MATrix LABoratory.
MATLAB has since been expanded and now has
built-in functions for solving problems requiring data
analysis, signal processing, optimization, and several
other types of scientific computations. It also
contains functions for 2-D and 3-D graphics and
animation.
5
MATLAB
Everything in MATLAB is a matrix !
6
MATLAB
 The MATLAB environment is command oriented
somewhat like UNIX. A prompt appears on the screen and
a MATLAB statement can be entered. When the <ENTER>
key is pressed, the statement is executed, and another
prompt appears.
 If a statement is terminated with a semicolon ( ; ), no
results will be displayed. Otherwise results will appear
before the next prompt.
What is Matlab?
 Matlab is basically a high level language
 which has many specialized toolboxes for making
things easier for us
 How high?
Assembly
High Level
Languages such as
C, Pascal etc.
Matlab
What are we interested in?
 Matlab is too broad for our purposes in this
course.
 The features we are going to require is
Matlab
Command
Line
m-files
functions
mat-files
Command execution
like DOS command
window
Series of
Matlab
commands
Input
Output
capability
Data
storage/
loading
Matlab Screen
 Command Window
 type commands
 Current Directory
 View folders and m-files
 Workspace
 View program variables
 Double click on a variable
to see it in the Array Editor
 Command History
 view past commands
 save a whole session
using diary
10
The MATLAB User Interface
11
MATLAB
To get started, type one of these commands: helpwin,
helpdesk, or demo
» a=5;
» b=a/2
b =
2.5000
»
12
MATLAB Variable Names
 Variable names ARE case sensitive
 Variable names can contain up to 63 characters (as of
MATLAB 6.5 and newer)
 Variable names must start with a letter followed by letters,
digits, and underscores.
13
MATLAB Special Variables
ans Default variable name for results
pi Value of 
eps Smallest incremental number
inf Infinity
NaN Not a number e.g. 0/0
i and j i = j = square root of -1
realmin The smallest usable positive real number
realmax The largest usable positive real number
14
Topics..
 What is MATLAB ??
 Basic Matrix Operations
 Script Files and M-files
 Some more Operations and Functions
APPLICATIONS:
 Plotting functions ..
 Image Processing Basics ..
 Robotics Applications ..
 GUI Design and Programming
15
Math & Assignment Operators
Power ^ or .^ a^b or a.^b
Multiplication * or .* a*b or a.*b
Division / or ./ a/b or a./b
or  or . ba or b.a
NOTE: 56/8 = 856
- (unary) + (unary)
Addition + a + b
Subtraction - a - b
Assignment = a = b (assign b to a)
16
Other MATLAB symbols
>> prompt
. . . continue statement on next line
, separate statements and data
% start comment which ends at end of line
; (1) suppress output
(2) used as a row separator in a matrix
: specify range
17
MATLAB Relational Operators
 MATLAB supports six relational operators.
Less Than <
Less Than or Equal <=
Greater Than >
Greater Than or Equal >=
Equal To ==
Not Equal To ~=
18
MATLAB Logical Operators
 MATLAB supports three logical operators.
not ~ % highest precedence
and & % equal precedence with or
or | % equal precedence with and
19
MATLAB Matrices
 MATLAB treats all variables as matrices. For our purposes
a matrix can be thought of as an array, in fact, that is how
it is stored.
 Vectors are special forms of matrices and contain only one
row OR one column.
 Scalars are matrices with only one row AND one column
20
MATLAB Matrices
 A matrix with only one row AND one column is a scalar. A
scalar can be created in MATLAB as follows:
» a_value=23
a_value =
23
21
MATLAB Matrices
 A matrix with only one row is called a row vector. A row
vector can be created in MATLAB as follows (note the
commas):
» rowvec = [12 , 14 , 63]
rowvec =
12 14 63
22
MATLAB Matrices
 A matrix with only one column is called a column vector.
A column vector can be created in MATLAB as follows
(note the semicolons):
» colvec = [13 ; 45 ; -2]
colvec =
13
45
-2
23
MATLAB Matrices
 A matrix can be created in MATLAB as follows (note the
commas AND semicolons):
» matrix = [1 , 2 , 3 ; 4 , 5 ,6 ; 7 , 8 , 9]
matrix =
1 2 3
4 5 6
7 8 9
24
Extracting a Sub-Matrix
 A portion of a matrix can be extracted and stored in a
smaller matrix by specifying the names of both matrices
and the rows and columns to extract. The syntax is:
sub_matrix = matrix ( r1 : r2 , c1 : c2 ) ;
where r1 and r2 specify the beginning and ending rows
and c1 and c2 specify the beginning and ending columns
to be extracted to make the new matrix.
25
MATLAB Matrices
 A column vector can be
extracted from a matrix.
As an example we create a
matrix below:
» matrix=[1,2,3;4,5,6;7,8,9]
matrix =
1 2 3
4 5 6
7 8 9
 Here we extract column 2
of the matrix and make a
column vector:
» col_two=matrix( : , 2)
col_two =
2
5
8
26
MATLAB Matrices
 A row vector can be
extracted from a matrix.
As an example we create
a matrix below:
» matrix=[1,2,3;4,5,6;7,8,9]
matrix =
1 2 3
4 5 6
7 8 9
 Here we extract row 2 of
the matrix and make a
row vector. Note that
the 2:2 specifies the
second row and the 1:3
specifies which columns
of the row.
» rowvec=matrix(2 : 2 , 1 :
3)
rowvec =
4 5 6
Array, Matrix
 a vector x = [1 2 5 1]
x =
1 2 5 1
 a matrix x = [1 2 3; 5 1 4; 3 2 -1]
x =
1 2 3
5 1 4
3 2 -1
 transpose y = x’ y =
1
2
5
1
Long Array, Matrix
 t =1:10
t =
1 2 3 4 5 6 7 8 9 10
 k =2:-0.5:-1
k =
2 1.5 1 0.5 0 -0.5 -1
 B = [1:4; 5:8]
x =
1 2 3 4
5 6 7 8
Generating Vectors from functions
 zeros(M,N) MxN matrix of zeros
 ones(M,N) MxN matrix of ones
 rand(M,N) MxN matrix of uniformly
distributed
random
numbers on (0,1)
x = zeros(1,3)
x =2
0 0 0
x = ones(1,3)
x =
1 1 1
x = rand(1,3)
x =
0.9501 0.2311 0.6068
Matrix Index The matrix indices begin from 1 (not 0 (as in C))
 The matrix indices must be positive integer
Given:
A(-2), A(0)
Error: ??? Subscript indices must either be real positive integers or logicals.
A(4,2)
Error: ??? Index exceeds matrix dimensions.
Concatenation of Matrices
 x = [1 2], y = [4 5], z=[ 0 0]
A = [ x y]
1 2 4 5
B = [x ; y]
1 2
4 5
C = [x y ;z]
Error:
??? Error using ==> vertcat CAT arguments dimensions are not consistent.
Matrices Operations
Given A and B:
Addition Subtraction Product Transpose
The use of “.” – “Element” Operation
K= x^2
Erorr:
??? Error using ==> mpower Matrix must be square.
B=x*y
Erorr:
??? Error using ==> mtimes Inner matrix dimensions must agree.
A = [1 2 3; 5 1 4; 3 2 1]
A =
1 2 3
5 1 4
3 2 -1
y = A(3 ,:)
y=
3 4 -1
b = x .* y
b=
3 8 -3
c = x . / y
c=
0.33 0.5 -3
d = x .^2
d=
1 4 9
x = A(1,:)
x=
1 2 3
Vectors and Matrices

















18
16
14
12
10
B
 How do we assign values to vectors?
>>> A = [1 2 3 4 5]
A =
1 2 3 4 5
>>>
>>> B = [10;12;14;16;18]
B =
10
12
14
16
18
>>>
A row vector –
values are
separated by
spaces
A column vector
– values are
separated by
semi–colon (;)
 54321A 
Vectors and Matrices
 How do we assign values to matrices ?
Columns separated by
space or a comma
Rows separated by
semi-colon
>>> A=[1 2 3;4 5 6;7 8 9]
A =
1 2 3
4 5 6
7 8 9
>>> 









987
654
321
Vectors and Matrices
 How do we access elements in a matrix or a vector?
Try the followings:
>>> A(2,3)
ans =
6
>>> A(:,3)
ans =
3
6
9
>>> A(1,:)
ans =
1 2 3
>>> A(2,:)
ans =
4 5 6
Vectors and Matrices
 Arithmetic operations – Matrices
Performing operations to every entry in a matrix
Add and subtract>>> A=[1 2 3;4 5 6;7 8
9]
A =
1 2 3
4 5 6
7 8 9
>>>
>>> A+3
ans =
4 5 6
7 8 9
10 11 12
>>> A-2
ans =
-1 0 1
2 3 4
5 6 7
Vectors and Matrices
 Arithmetic operations – Matrices
Performing operations to every entry in a matrix
Multiply and divide>>> A=[1 2 3;4 5 6;7 8 9]
A =
1 2 3
4 5 6
7 8 9
>>>
>>> A*2
ans =
2 4 6
8 10 12
14 16 18
>>> A/3
ans =
0.3333 0.6667 1.0000
1.3333 1.6667 2.0000
2.3333 2.6667 3.0000
Vectors and Matrices
 Arithmetic operations – Matrices
Performing operations to every entry in a matrix
Power
>>> A=[1 2 3;4 5 6;7 8 9]
A =
1 2 3
4 5 6
7 8 9
>>>
A^2 = A * A
To square every element in A, use
the element–wise operator .^
>>> A.^2
ans =
1 4 9
16 25 36
49 64 81
>>> A^2
ans =
30 36 42
66 81 96
102 126 150
Vectors and Matrices
 Arithmetic operations – Matrices
Performing operations between matrices
>>> A=[1 2 3;4 5 6;7 8 9]
A =
1 2 3
4 5 6
7 8 9
>>> B=[1 1 1;2 2 2;3 3 3]
B =
1 1 1
2 2 2
3 3 3
A*B 



















333
222
111
987
654
321
A.*B










3x93x83x7
2x62x52x4
1x31x21x1










272421
12108
321
=
=










505050
323232
141414
Vectors and Matrices
 Arithmetic operations – Matrices
Performing operations between matrices
A/B
A./B










0000.36667.23333.2
0000.35000.20000.2
0000.30000.20000.1
=
? (matrices
singular)










3/93/83/7
2/62/52/4
1/31/21/1
Vectors and Matrices
 Arithmetic operations – Matrices
Performing operations between matrices
A^B
A.^B










729512343
362516
321
=
??? Error using ==> ^
At least one operand must be scalar










333
222
111
987
654
321
Basic Task: Plot the function sin(x)
between 0≤x≤4π
 Create an x-array of 100 samples between 0 and 4π.
 Calculate sin(.) of the x-array
 Plot the y-array
>>x=linspace(0,4*pi,100);
>>y=sin(x);
>>plot(y)
0 10 20 30 40 50 60 70 80 90 100
-1
-0.8
-0.6
-0.4
-0.2
0
0.2
0.4
0.6
0.8
1
Plot the function e-x/3sin(x) between
0≤x≤4π Create an x-array of 100 samp
 Calculate sin(.) of the x-array
 Calculate e-x/3 of the x-array
 Multiply the arrays y and y1
>>x=linspace(0,4*pi,100);
>>y=sin(x);
>>y1=exp(-x/3);
>>y2=y*y1;
Display Facilities
 plot(.)
 stem(.)
Example:
>>x=linspace(0,4*pi,100);
>>y=sin(x);
>>plot(y)
>>plot(x,y)
Example:
>>stem(y)
>>stem(x,y)
0 10 20 30 40 50 60 70 80 90 100
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
0 10 20 30 40 50 60 70 80 90 100
-0.3
-0.2
-0.1
0
0.1
0.2
0.3
0.4
0.5
0.6
0.7
46
Topics..
 What is MATLAB ??
 Basic Matrix Operations
 Script Files and M-files
 Some more Operations and Functions
APPLICATIONS:
 Plotting functions ..
 Image Processing Basics ..
 Robotics Applications ..
 GUI Design and Programming
47
Use of M-File
 There are two kinds of M-files:
Scripts, which do not accept input
arguments or return output arguments. They
operate on data in the workspace.
Functions, which can accept input
arguments and return output arguments.
Internal variables are local to the function.
Click to create
a new M-File
48
M-File as script file
Save file as filename.m
Type what you want to
do, eg. Create matrices
If you include “;” at the
end of each statement,
result will not be shown
immediately
Run the file by typing the filename in the command window
49
Reading Data from files
 MATLAB supports reading an entire file and creating a
matrix of the data with one statement.
>> load mydata.dat; % loads file into matrix.
% The matrix may be a scalar, a vector, or a
% matrix with multiple rows and columns. The
% matrix will be named mydata.
>> size (mydata) % size will return the number
% of rows and number of
% columns in the matrix
>> length (myvector) % length will return the total
% no. of elements in
myvector
50
Some Useful MATLAB commands
 who List known variables
 whos List known variables plus their size
 help >> help sqrt Help on using sqrt
 lookfor >> lookfor sqrt Search for
keyword sqrt in m-files
 what >> what a: List MATLAB files in a:
 clear Clear all variables from work space
 clear x y Clear variables x and y from work space
 clc Clear the command window
51
Some Useful MATLAB commands
 what List all m-files in current directory
 dir List all files in current directory
 ls Same as dir
 type test Display test.m in command window
 delete test Delete test.m
 cd a: Change directory to a:
 chdir a: Same as cd
 pwd Show current directory
 which test Display directory path to ‘closest’
test.m
52
MATLAB Logical Functions
 MATLAB also supports some logical functions.
xor (exclusive or) Ex: xor (a, b)
Where a and b are logical expressions. The xor
operator evaluates to true if and only if one
expression is true and the other is false. True is
returned as 1, false as 0.
any (x) returns 1 if any element of x is nonzero
all (x) returns 1 if all elements of x are nonzero
isnan (x) returns 1 at each NaN in x
isinf (x) returns 1 at each infinity in x
finite (x) returns 1 at each finite value in x
53
Matlab Selection Structures
 An if - elseif - else structure in MATLAB.
Note that elseif is one word.
if expression1 % is true
% execute these commands
elseif expression2 % is true
% execute these commands
else % the default
% execute these commands
end
54
MATLAB Repetition Structures
A for loop in MATLAB for x = array
for ind = 1:100
b(ind)=sin(ind/10)
end
while loop in MATLAB while expression
while x <= 10
% execute these commands
end
x=0.1:0.1:10; b=sin(x); - Most of the loops can be
avoided!!!
55
Scalar - Matrix Addition
» a=3;
» b=[1, 2, 3;4, 5, 6]
b =
1 2 3
4 5 6
» c= b+a % Add a to each element of b
c =
4 5 6
7 8 9
56
Scalar - Matrix Subtraction
» a=3;
» b=[1, 2, 3;4, 5, 6]
b =
1 2 3
4 5 6
» c = b - a %Subtract a from each element of b
c =
-2 -1 0
1 2 3
57
Scalar - Matrix Multiplication
» a=3;
» b=[1, 2, 3; 4, 5, 6]
b =
1 2 3
4 5 6
» c = a * b % Multiply each element of b by a
c =
3 6 9
12 15 18
58
Scalar - Matrix Division
» a=3;
» b=[1, 2, 3; 4, 5, 6]
b =
1 2 3
4 5 6
» c = b / a % Divide each element of b by a
c =
0.3333 0.6667 1.0000
1.3333 1.6667 2.0000
59
The use of “.” – “Element” Operation
Given A:
Divide each element of
A by 2
Multiply each
element of A by 3
Square each
element of A
6060
MATLAB Toolboxes
 MATLAB has a number of add-on software modules, called
toolbox , that perform more specialized computations.
 Signal Processing
 Image Processing
 Communications
 System Identification
 Wavelet Filter Design
 Control System
 Fuzzy Logic
 Robust Control
 µ-Analysis and Synthesis
 LMI Control
 Model Predictive Control
 …
6161
MATLAB Demo
 Demonstrations are invaluable since they give an indication
of the MATLAB capabilities.
 A comprehensive set are available by typing the command
>>demo in MATLAB prompt.
62
An Interesting, MATLAB command
why
In case you ever needed a reason
63
Topics..
 What is MATLAB ??
 Basic Matrix Operations
 Script Files and M-files
 Some more Operations and Functions
APPLICATIONS:
 Plotting functions ..
 Image Processing Basics ..
 Robotics Applications ..
 GUI Design and Programming
64
Plot
PLOT Linear plot.
 PLOT(X,Y) plots vector Y
versus vector X
 PLOT(Y) plots the columns of
Y versus their index
 PLOT(X,Y,S) with plot
symbols and colors
 See also SEMILOGX,
SEMILOGY, TITLE,
XLABEL, YLABEL, AXIS,
AXES, HOLD, COLORDEF,
LEGEND, SUBPLOT...
x = [-3 -2 -1 0 1 2 3];
y1 = (x.^2) -1;
plot(x, y1,'bo-.');
Example
65
Plot Properties
XLABEL X-axis label.
 XLABEL('text') adds text
beside the X-axis on the
current axis.
YLABEL Y-axis label.
 YLABEL('text') adds text
beside the Y-axis on the
current axis.
...
xlabel('x values');
ylabel('y values');
Example
66
Hold
HOLD Hold current graph.
 HOLD ON holds the current
plot and all axis properties so
that subsequent graphing
commands add to the existing
graph.
 HOLD OFF returns to the
default mode
 HOLD, by itself, toggles the
hold state.
...
hold on;
y2 = x + 2;
plot(x, y2, 'g+:');
Example
67
Subplot
SUBPLOT Create axes in tiled
positions.
 SUBPLOT(m,n,p), or
SUBPLOT(mnp), breaks the Figure
window into an m-by-n matrix of
small axes
x = [-3 -2 -1 0 1 2 3];
y1 = (x.^2) -1;
% Plot y1 on the top
subplot(2,1,1);
plot(x, y1,'bo-.');
xlabel('x values');
ylabel('y values');
% Plot y2 on the bottom
subplot(2,1,2);
y2 = x + 2;
plot(x, y2, 'g+:');
Example
68
Figure
FIGURE Create figure window.
 FIGURE, by itself, creates a
new figure window, and
returns its handle.
x = [-3 -2 -1 0 1 2 3];
y1 = (x.^2) -1;
% Plot y1 in the 1st Figure
plot(x, y1,'bo-.');
xlabel('x values');
ylabel('y values');
% Plot y2 in the 2nd Figure
figure
y2 = x + 2;
plot(x, y2, 'g+:');
Example
69
Surface Plot
x = 0:0.1:2;
y = 0:0.1:2;
[xx, yy] = meshgrid(x,y);
zz=sin(xx.^2+yy.^2);
surf(xx,yy,zz)
xlabel('X axes')
ylabel('Y axes')
70
contourf-colorbar-plot3-waterfall-contour3-mesh-surf
3 D Surface Plot
71
Convolution
The behavior of a linear, continuous-time, time-invariant system with
input signal x(t) and output signal y(t) is described by the convolution
integral
- h(t), assumed known, the response of the system to a unit impulse
input
For example,
x = [1 1 1 1 1];  [1 1 1 1 1]
h = [0 1 2 3];  [3 2 1 0]
conv(x,h)
yields y = [0 1 3 6 6 6 5 3]
stem(y);
ylabel(‘Conv');
xlabel(‘sample number’);
72
Topics..
 What is MATLAB ??
 Basic Matrix Operations
 Script Files and M-files
 Some more Operations and Functions
APPLICATIONS:
 Plotting functions ..
 Image Processing Basics ..
 Robotics Applications ..
 GUI Design and Programming
7373
Image Processing Toolbox
 The Image Processing Toolbox is a collection of functions
that extend the capability of the MATLAB ® numeric
computing environment. The toolbox supports a wide
range of image processing operations, including:
 Geometric operations
 Neighborhood and block operations
 Linear filtering and filter design
 Transforms
 Image analysis and enhancement
 Binary image operations
 Region of interest operations
7474
MATLAB Image Types
 Indexed images : m-by-3 color map
 Intensity images : [0,1] or uint8
 Binary images : {0,1}
 RGB images : m-by-n-by-3
7575
Indexed Images
» [x,map] =
imread('trees.tif');
» imshow(x,map);
7676
Intensity Images
» image =
ind2gray(x,map);
» imshow(image);
7777
Binary Images
» imshow(edge(image));
7878
RGB Images
7979
Image Display
 image - create and display image object
 imagesc - scale and display as image
 imshow - display image
 colorbar - display colorbar
 getimage- get image data from axes
 truesize - adjust display size of image
 zoom - zoom in and zoom out of 2D plot
8080
Image Conversion
 Gray2ind - intensity image to index image
 im2bw - image to binary
 Im2double - image to double precision
 Im2uint8 - image to 8-bit unsigned integers
 Im2uint16 - image to 16-bit unsigned integers
 Ind2gray - indexed image to intensity image
 mat2gray - matrix to intensity image
 rgb2gray - RGB image to grayscale
 rgb2ind - RGB image to indexed image
81
GEOMETRIC OPERATIONS
“imcrop” crops an image to a specified rectangle.
imcrop displays the input image and waits for you to
specify the crop rectangle with the mouse.
82
IMAGE ENHANCEMENT
 Adjust intensity
 imadjust
 histeq
 Noise removal
 linear filtering
 median filtering
 adaptive filtering
>>im2 = histeq(im);
>>imshow(im2)
8383
TRANSFORMS
Fourier Transform
-fft2, fftshift, ifft2
Discrete Cosine Transform (DCT)
-dct2, idct2, dctmtx, dctdemo
Radon Transform
-radon, iradon, phantom
84
Topics..
 What is MATLAB ??
 Basic Matrix Operations
 Script Files and M-files
 Some more Operations and Functions
APPLICATIONS:
 Plotting functions ..
 Image Processing Basics ..
 Robotics Applications ..
 GUI Design and Programming
85
Robotics Application
Lez Concorrenza - The Automation-Robotics Event, Techniche 2005
86
Robotics Application
Concept
 take image
 filter using medfilt2
 take the subarray of ball region, find cluster of max
area ,find its centroid
 take the subarray of robot region , find cluster of max
area, find its centroid
 interpolate the ball using the ball's current and
previous coordinate , give output
87
Robotics Application
MATLAB Code
parport=digitalio('parallel','LPT1');
addline(parport,0:7,'out');
ball_x_prev = 1;
ball_y_prev = 1;
while (1)
% code for acquiring image
filtered_image=medfilt2(bw,[3 3]); % filter the image
region_ball = filtered_image[20:460,10:575]; % ball region
region_bot = filtered_image[20:460,575:630]; % robot region
label = bwlabel(region_ball,4); %label the clusters in the region
data = regionprops(label,'basic'); % data ontains properties of clusters in the region
object = find([data.Area]==max([data.Area])) % object conatains the label of the cluster with max
area
88
Robotics Application
ball_x = data(object).Centroid(1); %x coordinates of the ball
ball_y = data(object).Centroid(2);
label = bwlabel(region_bot,4); %label the clusters in the region
data = regionprops(label,'basic'); % data ontains properties of clusters in the region
object =find([data.Area]==max([data.Area])) % object conatains the label of the cluster with max
area
robot_x = data(object).Centroid(1); %x coordinates of the bot
robot_y = data(object).Centroid(2);
% Algorithm for movement of robot
if (ball_x > ball_x_prev) % the ball is returning to the bot
% Do something
if (robot_y > y_proj)
% Do something else
Etc.
89
Topics..
 What is MATLAB ??
 Basic Matrix Operations
 Script Files and M-files
 Some more Operations and Functions
APPLICATIONS:
 Plotting functions ..
 Image Processing Basics ..
 Robotics Applications ..
 GUI Design and Programming
90
Graphical User Interface
What is GUI: A graphical user interface (GUI) is a
user interface built with graphical objects such as
 Buttons
 Text fields
 Sliders
 Menus
If the GUI is designed well-designed, it should be
intuitively obvious to the user how its components
function.
91
Push ButtonsRadio Buttons
Frames
Checkbox Slider
Edit text
static textAxes
92
Graphical User Interface
Guide Editor
Property InspectorResult Figure
93
GUI: Spectrum Analyzer
94
Thanks
Questions ??

Weitere ähnliche Inhalte

Was ist angesagt?

Matlab m files and scripts
Matlab m files and scriptsMatlab m files and scripts
Matlab m files and scriptsAmeen San
 
MODEL DRIVEN DEVELOPMENT (1).pptx
MODEL DRIVEN DEVELOPMENT (1).pptxMODEL DRIVEN DEVELOPMENT (1).pptx
MODEL DRIVEN DEVELOPMENT (1).pptxpawan745387
 
Compiler Construction Course - Introduction
Compiler Construction Course - IntroductionCompiler Construction Course - Introduction
Compiler Construction Course - IntroductionMuhammad Sanaullah
 
Principles of programming
Principles of programmingPrinciples of programming
Principles of programmingRob Paok
 
C Programming Lab manual 18CPL17
C Programming Lab manual 18CPL17C Programming Lab manual 18CPL17
C Programming Lab manual 18CPL17manjurkts
 
Scientific calculator project in c language
Scientific calculator project in c languageScientific calculator project in c language
Scientific calculator project in c languageAMIT KUMAR
 
Evolution of Programming Languages
Evolution of Programming LanguagesEvolution of Programming Languages
Evolution of Programming LanguagesSayanee Basu
 
2. Array in Data Structure
2. Array in Data Structure2. Array in Data Structure
2. Array in Data StructureMandeep Singh
 
A presentation on software crisis
A presentation on software crisisA presentation on software crisis
A presentation on software crisischandan sharma
 
Programming languages
Programming languagesProgramming languages
Programming languagesSimon Mui
 
RMMM-Risk Management,Mitigation and Monitoring.
RMMM-Risk Management,Mitigation and Monitoring.RMMM-Risk Management,Mitigation and Monitoring.
RMMM-Risk Management,Mitigation and Monitoring.Aparna Nayak
 
Java Media Framework API
Java Media Framework APIJava Media Framework API
Java Media Framework APIelliando dias
 
Chomsky classification of Language
Chomsky classification of LanguageChomsky classification of Language
Chomsky classification of LanguageDipankar Boruah
 
02 order of growth
02 order of growth02 order of growth
02 order of growthHira Gul
 

Was ist angesagt? (20)

Matlab m files and scripts
Matlab m files and scriptsMatlab m files and scripts
Matlab m files and scripts
 
Dictionaries in Python
Dictionaries in PythonDictionaries in Python
Dictionaries in Python
 
Matlab-fundamentals of matlab-2
Matlab-fundamentals of matlab-2Matlab-fundamentals of matlab-2
Matlab-fundamentals of matlab-2
 
MODEL DRIVEN DEVELOPMENT (1).pptx
MODEL DRIVEN DEVELOPMENT (1).pptxMODEL DRIVEN DEVELOPMENT (1).pptx
MODEL DRIVEN DEVELOPMENT (1).pptx
 
Compiler Construction Course - Introduction
Compiler Construction Course - IntroductionCompiler Construction Course - Introduction
Compiler Construction Course - Introduction
 
Principles of programming
Principles of programmingPrinciples of programming
Principles of programming
 
C Programming Lab manual 18CPL17
C Programming Lab manual 18CPL17C Programming Lab manual 18CPL17
C Programming Lab manual 18CPL17
 
MACRO PROCESSOR
MACRO PROCESSORMACRO PROCESSOR
MACRO PROCESSOR
 
Computer Programming
Computer ProgrammingComputer Programming
Computer Programming
 
Scientific calculator project in c language
Scientific calculator project in c languageScientific calculator project in c language
Scientific calculator project in c language
 
Evolution of Programming Languages
Evolution of Programming LanguagesEvolution of Programming Languages
Evolution of Programming Languages
 
2. Array in Data Structure
2. Array in Data Structure2. Array in Data Structure
2. Array in Data Structure
 
A presentation on software crisis
A presentation on software crisisA presentation on software crisis
A presentation on software crisis
 
Programming languages
Programming languagesProgramming languages
Programming languages
 
RMMM-Risk Management,Mitigation and Monitoring.
RMMM-Risk Management,Mitigation and Monitoring.RMMM-Risk Management,Mitigation and Monitoring.
RMMM-Risk Management,Mitigation and Monitoring.
 
Oop
OopOop
Oop
 
Java Media Framework API
Java Media Framework APIJava Media Framework API
Java Media Framework API
 
Chomsky classification of Language
Chomsky classification of LanguageChomsky classification of Language
Chomsky classification of Language
 
Pseudo code
Pseudo codePseudo code
Pseudo code
 
02 order of growth
02 order of growth02 order of growth
02 order of growth
 

Ähnlich wie Matlab introduction

Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab sessionDr. Krishna Mohbey
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxprashantkumarchinama
 
matlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsxmatlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsxlekhacce
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersMurshida ck
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arraysAmeen San
 
1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptxBeheraA
 
From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondFrom zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondMahuaPal6
 
Lines and planes in space
Lines and planes in spaceLines and planes in space
Lines and planes in spaceFaizan Shabbir
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabDnyanesh Patil
 
Introduction to Matlab.pdf
Introduction to Matlab.pdfIntroduction to Matlab.pdf
Introduction to Matlab.pdfssuser43b38e
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlabSantosh V
 
Introduction to matlab lecture 2 of 4
Introduction to matlab lecture 2 of 4Introduction to matlab lecture 2 of 4
Introduction to matlab lecture 2 of 4Randa Elanwar
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlabkrajeshk1980
 

Ähnlich wie Matlab introduction (20)

Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Matlab anilkumar
Matlab  anilkumarMatlab  anilkumar
Matlab anilkumar
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
 
Matlab
MatlabMatlab
Matlab
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
 
matlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsxmatlab-130408153714-phpapp02_lab123.ppsx
matlab-130408153714-phpapp02_lab123.ppsx
 
Matlab-1.pptx
Matlab-1.pptxMatlab-1.pptx
Matlab-1.pptx
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arrays
 
Matlab ppt
Matlab pptMatlab ppt
Matlab ppt
 
1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx1.1Introduction to matlab.pptx
1.1Introduction to matlab.pptx
 
From zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyondFrom zero to MATLAB hero: Mastering the basics and beyond
From zero to MATLAB hero: Mastering the basics and beyond
 
Lines and planes in space
Lines and planes in spaceLines and planes in space
Lines and planes in space
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
MATLAB INTRODUCTION
MATLAB INTRODUCTIONMATLAB INTRODUCTION
MATLAB INTRODUCTION
 
Introduction to Matlab.pdf
Introduction to Matlab.pdfIntroduction to Matlab.pdf
Introduction to Matlab.pdf
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Introduction to matlab lecture 2 of 4
Introduction to matlab lecture 2 of 4Introduction to matlab lecture 2 of 4
Introduction to matlab lecture 2 of 4
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
 

Kürzlich hochgeladen

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfciinovamais
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...EduSkills OECD
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...christianmathematics
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhikauryashika82
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDThiyagu K
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfagholdier
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...fonyou31
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 

Kürzlich hochgeladen (20)

Activity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdfActivity 01 - Artificial Culture (1).pdf
Activity 01 - Artificial Culture (1).pdf
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
Presentation by Andreas Schleicher Tackling the School Absenteeism Crisis 30 ...
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
Explore beautiful and ugly buildings. Mathematics helps us create beautiful d...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in DelhiRussian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
Russian Escort Service in Delhi 11k Hotel Foreigner Russian Call Girls in Delhi
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Measures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SDMeasures of Dispersion and Variability: Range, QD, AD and SD
Measures of Dispersion and Variability: Range, QD, AD and SD
 
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
Mattingly "AI & Prompt Design: Structured Data, Assistants, & RAG"
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
Ecosystem Interactions Class Discussion Presentation in Blue Green Lined Styl...
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 

Matlab introduction

  • 2. 2 Topics..  What is MATLAB ??  Basic Matrix Operations  Script Files and M-files  Some more Operations and Functions APPLICATIONS:  Plotting functions ..  Image Processing Basics ..  Robotics Applications ..
  • 3. 3 Topics..  What is MATLAB ??  Basic Matrix Operations  Script Files and M-files  Some more Operations and Functions APPLICATIONS:  Plotting functions ..  Image Processing Basics ..  Robotics Applications ..
  • 4. 4 MATLAB  MATLAB is a program for doing numerical computation. It was originally designed for solving linear algebra type problems using matrices. It’s name is derived from MATrix LABoratory. MATLAB has since been expanded and now has built-in functions for solving problems requiring data analysis, signal processing, optimization, and several other types of scientific computations. It also contains functions for 2-D and 3-D graphics and animation.
  • 6. 6 MATLAB  The MATLAB environment is command oriented somewhat like UNIX. A prompt appears on the screen and a MATLAB statement can be entered. When the <ENTER> key is pressed, the statement is executed, and another prompt appears.  If a statement is terminated with a semicolon ( ; ), no results will be displayed. Otherwise results will appear before the next prompt.
  • 7. What is Matlab?  Matlab is basically a high level language  which has many specialized toolboxes for making things easier for us  How high? Assembly High Level Languages such as C, Pascal etc. Matlab
  • 8. What are we interested in?  Matlab is too broad for our purposes in this course.  The features we are going to require is Matlab Command Line m-files functions mat-files Command execution like DOS command window Series of Matlab commands Input Output capability Data storage/ loading
  • 9. Matlab Screen  Command Window  type commands  Current Directory  View folders and m-files  Workspace  View program variables  Double click on a variable to see it in the Array Editor  Command History  view past commands  save a whole session using diary
  • 10. 10 The MATLAB User Interface
  • 11. 11 MATLAB To get started, type one of these commands: helpwin, helpdesk, or demo » a=5; » b=a/2 b = 2.5000 »
  • 12. 12 MATLAB Variable Names  Variable names ARE case sensitive  Variable names can contain up to 63 characters (as of MATLAB 6.5 and newer)  Variable names must start with a letter followed by letters, digits, and underscores.
  • 13. 13 MATLAB Special Variables ans Default variable name for results pi Value of  eps Smallest incremental number inf Infinity NaN Not a number e.g. 0/0 i and j i = j = square root of -1 realmin The smallest usable positive real number realmax The largest usable positive real number
  • 14. 14 Topics..  What is MATLAB ??  Basic Matrix Operations  Script Files and M-files  Some more Operations and Functions APPLICATIONS:  Plotting functions ..  Image Processing Basics ..  Robotics Applications ..  GUI Design and Programming
  • 15. 15 Math & Assignment Operators Power ^ or .^ a^b or a.^b Multiplication * or .* a*b or a.*b Division / or ./ a/b or a./b or or . ba or b.a NOTE: 56/8 = 856 - (unary) + (unary) Addition + a + b Subtraction - a - b Assignment = a = b (assign b to a)
  • 16. 16 Other MATLAB symbols >> prompt . . . continue statement on next line , separate statements and data % start comment which ends at end of line ; (1) suppress output (2) used as a row separator in a matrix : specify range
  • 17. 17 MATLAB Relational Operators  MATLAB supports six relational operators. Less Than < Less Than or Equal <= Greater Than > Greater Than or Equal >= Equal To == Not Equal To ~=
  • 18. 18 MATLAB Logical Operators  MATLAB supports three logical operators. not ~ % highest precedence and & % equal precedence with or or | % equal precedence with and
  • 19. 19 MATLAB Matrices  MATLAB treats all variables as matrices. For our purposes a matrix can be thought of as an array, in fact, that is how it is stored.  Vectors are special forms of matrices and contain only one row OR one column.  Scalars are matrices with only one row AND one column
  • 20. 20 MATLAB Matrices  A matrix with only one row AND one column is a scalar. A scalar can be created in MATLAB as follows: » a_value=23 a_value = 23
  • 21. 21 MATLAB Matrices  A matrix with only one row is called a row vector. A row vector can be created in MATLAB as follows (note the commas): » rowvec = [12 , 14 , 63] rowvec = 12 14 63
  • 22. 22 MATLAB Matrices  A matrix with only one column is called a column vector. A column vector can be created in MATLAB as follows (note the semicolons): » colvec = [13 ; 45 ; -2] colvec = 13 45 -2
  • 23. 23 MATLAB Matrices  A matrix can be created in MATLAB as follows (note the commas AND semicolons): » matrix = [1 , 2 , 3 ; 4 , 5 ,6 ; 7 , 8 , 9] matrix = 1 2 3 4 5 6 7 8 9
  • 24. 24 Extracting a Sub-Matrix  A portion of a matrix can be extracted and stored in a smaller matrix by specifying the names of both matrices and the rows and columns to extract. The syntax is: sub_matrix = matrix ( r1 : r2 , c1 : c2 ) ; where r1 and r2 specify the beginning and ending rows and c1 and c2 specify the beginning and ending columns to be extracted to make the new matrix.
  • 25. 25 MATLAB Matrices  A column vector can be extracted from a matrix. As an example we create a matrix below: » matrix=[1,2,3;4,5,6;7,8,9] matrix = 1 2 3 4 5 6 7 8 9  Here we extract column 2 of the matrix and make a column vector: » col_two=matrix( : , 2) col_two = 2 5 8
  • 26. 26 MATLAB Matrices  A row vector can be extracted from a matrix. As an example we create a matrix below: » matrix=[1,2,3;4,5,6;7,8,9] matrix = 1 2 3 4 5 6 7 8 9  Here we extract row 2 of the matrix and make a row vector. Note that the 2:2 specifies the second row and the 1:3 specifies which columns of the row. » rowvec=matrix(2 : 2 , 1 : 3) rowvec = 4 5 6
  • 27. Array, Matrix  a vector x = [1 2 5 1] x = 1 2 5 1  a matrix x = [1 2 3; 5 1 4; 3 2 -1] x = 1 2 3 5 1 4 3 2 -1  transpose y = x’ y = 1 2 5 1
  • 28. Long Array, Matrix  t =1:10 t = 1 2 3 4 5 6 7 8 9 10  k =2:-0.5:-1 k = 2 1.5 1 0.5 0 -0.5 -1  B = [1:4; 5:8] x = 1 2 3 4 5 6 7 8
  • 29. Generating Vectors from functions  zeros(M,N) MxN matrix of zeros  ones(M,N) MxN matrix of ones  rand(M,N) MxN matrix of uniformly distributed random numbers on (0,1) x = zeros(1,3) x =2 0 0 0 x = ones(1,3) x = 1 1 1 x = rand(1,3) x = 0.9501 0.2311 0.6068
  • 30. Matrix Index The matrix indices begin from 1 (not 0 (as in C))  The matrix indices must be positive integer Given: A(-2), A(0) Error: ??? Subscript indices must either be real positive integers or logicals. A(4,2) Error: ??? Index exceeds matrix dimensions.
  • 31. Concatenation of Matrices  x = [1 2], y = [4 5], z=[ 0 0] A = [ x y] 1 2 4 5 B = [x ; y] 1 2 4 5 C = [x y ;z] Error: ??? Error using ==> vertcat CAT arguments dimensions are not consistent.
  • 32. Matrices Operations Given A and B: Addition Subtraction Product Transpose
  • 33. The use of “.” – “Element” Operation K= x^2 Erorr: ??? Error using ==> mpower Matrix must be square. B=x*y Erorr: ??? Error using ==> mtimes Inner matrix dimensions must agree. A = [1 2 3; 5 1 4; 3 2 1] A = 1 2 3 5 1 4 3 2 -1 y = A(3 ,:) y= 3 4 -1 b = x .* y b= 3 8 -3 c = x . / y c= 0.33 0.5 -3 d = x .^2 d= 1 4 9 x = A(1,:) x= 1 2 3
  • 34. Vectors and Matrices                  18 16 14 12 10 B  How do we assign values to vectors? >>> A = [1 2 3 4 5] A = 1 2 3 4 5 >>> >>> B = [10;12;14;16;18] B = 10 12 14 16 18 >>> A row vector – values are separated by spaces A column vector – values are separated by semi–colon (;)  54321A 
  • 35. Vectors and Matrices  How do we assign values to matrices ? Columns separated by space or a comma Rows separated by semi-colon >>> A=[1 2 3;4 5 6;7 8 9] A = 1 2 3 4 5 6 7 8 9 >>>           987 654 321
  • 36. Vectors and Matrices  How do we access elements in a matrix or a vector? Try the followings: >>> A(2,3) ans = 6 >>> A(:,3) ans = 3 6 9 >>> A(1,:) ans = 1 2 3 >>> A(2,:) ans = 4 5 6
  • 37. Vectors and Matrices  Arithmetic operations – Matrices Performing operations to every entry in a matrix Add and subtract>>> A=[1 2 3;4 5 6;7 8 9] A = 1 2 3 4 5 6 7 8 9 >>> >>> A+3 ans = 4 5 6 7 8 9 10 11 12 >>> A-2 ans = -1 0 1 2 3 4 5 6 7
  • 38. Vectors and Matrices  Arithmetic operations – Matrices Performing operations to every entry in a matrix Multiply and divide>>> A=[1 2 3;4 5 6;7 8 9] A = 1 2 3 4 5 6 7 8 9 >>> >>> A*2 ans = 2 4 6 8 10 12 14 16 18 >>> A/3 ans = 0.3333 0.6667 1.0000 1.3333 1.6667 2.0000 2.3333 2.6667 3.0000
  • 39. Vectors and Matrices  Arithmetic operations – Matrices Performing operations to every entry in a matrix Power >>> A=[1 2 3;4 5 6;7 8 9] A = 1 2 3 4 5 6 7 8 9 >>> A^2 = A * A To square every element in A, use the element–wise operator .^ >>> A.^2 ans = 1 4 9 16 25 36 49 64 81 >>> A^2 ans = 30 36 42 66 81 96 102 126 150
  • 40. Vectors and Matrices  Arithmetic operations – Matrices Performing operations between matrices >>> A=[1 2 3;4 5 6;7 8 9] A = 1 2 3 4 5 6 7 8 9 >>> B=[1 1 1;2 2 2;3 3 3] B = 1 1 1 2 2 2 3 3 3 A*B                     333 222 111 987 654 321 A.*B           3x93x83x7 2x62x52x4 1x31x21x1           272421 12108 321 = =           505050 323232 141414
  • 41. Vectors and Matrices  Arithmetic operations – Matrices Performing operations between matrices A/B A./B           0000.36667.23333.2 0000.35000.20000.2 0000.30000.20000.1 = ? (matrices singular)           3/93/83/7 2/62/52/4 1/31/21/1
  • 42. Vectors and Matrices  Arithmetic operations – Matrices Performing operations between matrices A^B A.^B           729512343 362516 321 = ??? Error using ==> ^ At least one operand must be scalar           333 222 111 987 654 321
  • 43. Basic Task: Plot the function sin(x) between 0≤x≤4π  Create an x-array of 100 samples between 0 and 4π.  Calculate sin(.) of the x-array  Plot the y-array >>x=linspace(0,4*pi,100); >>y=sin(x); >>plot(y) 0 10 20 30 40 50 60 70 80 90 100 -1 -0.8 -0.6 -0.4 -0.2 0 0.2 0.4 0.6 0.8 1
  • 44. Plot the function e-x/3sin(x) between 0≤x≤4π Create an x-array of 100 samp  Calculate sin(.) of the x-array  Calculate e-x/3 of the x-array  Multiply the arrays y and y1 >>x=linspace(0,4*pi,100); >>y=sin(x); >>y1=exp(-x/3); >>y2=y*y1;
  • 45. Display Facilities  plot(.)  stem(.) Example: >>x=linspace(0,4*pi,100); >>y=sin(x); >>plot(y) >>plot(x,y) Example: >>stem(y) >>stem(x,y) 0 10 20 30 40 50 60 70 80 90 100 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0 10 20 30 40 50 60 70 80 90 100 -0.3 -0.2 -0.1 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7
  • 46. 46 Topics..  What is MATLAB ??  Basic Matrix Operations  Script Files and M-files  Some more Operations and Functions APPLICATIONS:  Plotting functions ..  Image Processing Basics ..  Robotics Applications ..  GUI Design and Programming
  • 47. 47 Use of M-File  There are two kinds of M-files: Scripts, which do not accept input arguments or return output arguments. They operate on data in the workspace. Functions, which can accept input arguments and return output arguments. Internal variables are local to the function. Click to create a new M-File
  • 48. 48 M-File as script file Save file as filename.m Type what you want to do, eg. Create matrices If you include “;” at the end of each statement, result will not be shown immediately Run the file by typing the filename in the command window
  • 49. 49 Reading Data from files  MATLAB supports reading an entire file and creating a matrix of the data with one statement. >> load mydata.dat; % loads file into matrix. % The matrix may be a scalar, a vector, or a % matrix with multiple rows and columns. The % matrix will be named mydata. >> size (mydata) % size will return the number % of rows and number of % columns in the matrix >> length (myvector) % length will return the total % no. of elements in myvector
  • 50. 50 Some Useful MATLAB commands  who List known variables  whos List known variables plus their size  help >> help sqrt Help on using sqrt  lookfor >> lookfor sqrt Search for keyword sqrt in m-files  what >> what a: List MATLAB files in a:  clear Clear all variables from work space  clear x y Clear variables x and y from work space  clc Clear the command window
  • 51. 51 Some Useful MATLAB commands  what List all m-files in current directory  dir List all files in current directory  ls Same as dir  type test Display test.m in command window  delete test Delete test.m  cd a: Change directory to a:  chdir a: Same as cd  pwd Show current directory  which test Display directory path to ‘closest’ test.m
  • 52. 52 MATLAB Logical Functions  MATLAB also supports some logical functions. xor (exclusive or) Ex: xor (a, b) Where a and b are logical expressions. The xor operator evaluates to true if and only if one expression is true and the other is false. True is returned as 1, false as 0. any (x) returns 1 if any element of x is nonzero all (x) returns 1 if all elements of x are nonzero isnan (x) returns 1 at each NaN in x isinf (x) returns 1 at each infinity in x finite (x) returns 1 at each finite value in x
  • 53. 53 Matlab Selection Structures  An if - elseif - else structure in MATLAB. Note that elseif is one word. if expression1 % is true % execute these commands elseif expression2 % is true % execute these commands else % the default % execute these commands end
  • 54. 54 MATLAB Repetition Structures A for loop in MATLAB for x = array for ind = 1:100 b(ind)=sin(ind/10) end while loop in MATLAB while expression while x <= 10 % execute these commands end x=0.1:0.1:10; b=sin(x); - Most of the loops can be avoided!!!
  • 55. 55 Scalar - Matrix Addition » a=3; » b=[1, 2, 3;4, 5, 6] b = 1 2 3 4 5 6 » c= b+a % Add a to each element of b c = 4 5 6 7 8 9
  • 56. 56 Scalar - Matrix Subtraction » a=3; » b=[1, 2, 3;4, 5, 6] b = 1 2 3 4 5 6 » c = b - a %Subtract a from each element of b c = -2 -1 0 1 2 3
  • 57. 57 Scalar - Matrix Multiplication » a=3; » b=[1, 2, 3; 4, 5, 6] b = 1 2 3 4 5 6 » c = a * b % Multiply each element of b by a c = 3 6 9 12 15 18
  • 58. 58 Scalar - Matrix Division » a=3; » b=[1, 2, 3; 4, 5, 6] b = 1 2 3 4 5 6 » c = b / a % Divide each element of b by a c = 0.3333 0.6667 1.0000 1.3333 1.6667 2.0000
  • 59. 59 The use of “.” – “Element” Operation Given A: Divide each element of A by 2 Multiply each element of A by 3 Square each element of A
  • 60. 6060 MATLAB Toolboxes  MATLAB has a number of add-on software modules, called toolbox , that perform more specialized computations.  Signal Processing  Image Processing  Communications  System Identification  Wavelet Filter Design  Control System  Fuzzy Logic  Robust Control  µ-Analysis and Synthesis  LMI Control  Model Predictive Control  …
  • 61. 6161 MATLAB Demo  Demonstrations are invaluable since they give an indication of the MATLAB capabilities.  A comprehensive set are available by typing the command >>demo in MATLAB prompt.
  • 62. 62 An Interesting, MATLAB command why In case you ever needed a reason
  • 63. 63 Topics..  What is MATLAB ??  Basic Matrix Operations  Script Files and M-files  Some more Operations and Functions APPLICATIONS:  Plotting functions ..  Image Processing Basics ..  Robotics Applications ..  GUI Design and Programming
  • 64. 64 Plot PLOT Linear plot.  PLOT(X,Y) plots vector Y versus vector X  PLOT(Y) plots the columns of Y versus their index  PLOT(X,Y,S) with plot symbols and colors  See also SEMILOGX, SEMILOGY, TITLE, XLABEL, YLABEL, AXIS, AXES, HOLD, COLORDEF, LEGEND, SUBPLOT... x = [-3 -2 -1 0 1 2 3]; y1 = (x.^2) -1; plot(x, y1,'bo-.'); Example
  • 65. 65 Plot Properties XLABEL X-axis label.  XLABEL('text') adds text beside the X-axis on the current axis. YLABEL Y-axis label.  YLABEL('text') adds text beside the Y-axis on the current axis. ... xlabel('x values'); ylabel('y values'); Example
  • 66. 66 Hold HOLD Hold current graph.  HOLD ON holds the current plot and all axis properties so that subsequent graphing commands add to the existing graph.  HOLD OFF returns to the default mode  HOLD, by itself, toggles the hold state. ... hold on; y2 = x + 2; plot(x, y2, 'g+:'); Example
  • 67. 67 Subplot SUBPLOT Create axes in tiled positions.  SUBPLOT(m,n,p), or SUBPLOT(mnp), breaks the Figure window into an m-by-n matrix of small axes x = [-3 -2 -1 0 1 2 3]; y1 = (x.^2) -1; % Plot y1 on the top subplot(2,1,1); plot(x, y1,'bo-.'); xlabel('x values'); ylabel('y values'); % Plot y2 on the bottom subplot(2,1,2); y2 = x + 2; plot(x, y2, 'g+:'); Example
  • 68. 68 Figure FIGURE Create figure window.  FIGURE, by itself, creates a new figure window, and returns its handle. x = [-3 -2 -1 0 1 2 3]; y1 = (x.^2) -1; % Plot y1 in the 1st Figure plot(x, y1,'bo-.'); xlabel('x values'); ylabel('y values'); % Plot y2 in the 2nd Figure figure y2 = x + 2; plot(x, y2, 'g+:'); Example
  • 69. 69 Surface Plot x = 0:0.1:2; y = 0:0.1:2; [xx, yy] = meshgrid(x,y); zz=sin(xx.^2+yy.^2); surf(xx,yy,zz) xlabel('X axes') ylabel('Y axes')
  • 71. 71 Convolution The behavior of a linear, continuous-time, time-invariant system with input signal x(t) and output signal y(t) is described by the convolution integral - h(t), assumed known, the response of the system to a unit impulse input For example, x = [1 1 1 1 1];  [1 1 1 1 1] h = [0 1 2 3];  [3 2 1 0] conv(x,h) yields y = [0 1 3 6 6 6 5 3] stem(y); ylabel(‘Conv'); xlabel(‘sample number’);
  • 72. 72 Topics..  What is MATLAB ??  Basic Matrix Operations  Script Files and M-files  Some more Operations and Functions APPLICATIONS:  Plotting functions ..  Image Processing Basics ..  Robotics Applications ..  GUI Design and Programming
  • 73. 7373 Image Processing Toolbox  The Image Processing Toolbox is a collection of functions that extend the capability of the MATLAB ® numeric computing environment. The toolbox supports a wide range of image processing operations, including:  Geometric operations  Neighborhood and block operations  Linear filtering and filter design  Transforms  Image analysis and enhancement  Binary image operations  Region of interest operations
  • 74. 7474 MATLAB Image Types  Indexed images : m-by-3 color map  Intensity images : [0,1] or uint8  Binary images : {0,1}  RGB images : m-by-n-by-3
  • 75. 7575 Indexed Images » [x,map] = imread('trees.tif'); » imshow(x,map);
  • 76. 7676 Intensity Images » image = ind2gray(x,map); » imshow(image);
  • 79. 7979 Image Display  image - create and display image object  imagesc - scale and display as image  imshow - display image  colorbar - display colorbar  getimage- get image data from axes  truesize - adjust display size of image  zoom - zoom in and zoom out of 2D plot
  • 80. 8080 Image Conversion  Gray2ind - intensity image to index image  im2bw - image to binary  Im2double - image to double precision  Im2uint8 - image to 8-bit unsigned integers  Im2uint16 - image to 16-bit unsigned integers  Ind2gray - indexed image to intensity image  mat2gray - matrix to intensity image  rgb2gray - RGB image to grayscale  rgb2ind - RGB image to indexed image
  • 81. 81 GEOMETRIC OPERATIONS “imcrop” crops an image to a specified rectangle. imcrop displays the input image and waits for you to specify the crop rectangle with the mouse.
  • 82. 82 IMAGE ENHANCEMENT  Adjust intensity  imadjust  histeq  Noise removal  linear filtering  median filtering  adaptive filtering >>im2 = histeq(im); >>imshow(im2)
  • 83. 8383 TRANSFORMS Fourier Transform -fft2, fftshift, ifft2 Discrete Cosine Transform (DCT) -dct2, idct2, dctmtx, dctdemo Radon Transform -radon, iradon, phantom
  • 84. 84 Topics..  What is MATLAB ??  Basic Matrix Operations  Script Files and M-files  Some more Operations and Functions APPLICATIONS:  Plotting functions ..  Image Processing Basics ..  Robotics Applications ..  GUI Design and Programming
  • 85. 85 Robotics Application Lez Concorrenza - The Automation-Robotics Event, Techniche 2005
  • 86. 86 Robotics Application Concept  take image  filter using medfilt2  take the subarray of ball region, find cluster of max area ,find its centroid  take the subarray of robot region , find cluster of max area, find its centroid  interpolate the ball using the ball's current and previous coordinate , give output
  • 87. 87 Robotics Application MATLAB Code parport=digitalio('parallel','LPT1'); addline(parport,0:7,'out'); ball_x_prev = 1; ball_y_prev = 1; while (1) % code for acquiring image filtered_image=medfilt2(bw,[3 3]); % filter the image region_ball = filtered_image[20:460,10:575]; % ball region region_bot = filtered_image[20:460,575:630]; % robot region label = bwlabel(region_ball,4); %label the clusters in the region data = regionprops(label,'basic'); % data ontains properties of clusters in the region object = find([data.Area]==max([data.Area])) % object conatains the label of the cluster with max area
  • 88. 88 Robotics Application ball_x = data(object).Centroid(1); %x coordinates of the ball ball_y = data(object).Centroid(2); label = bwlabel(region_bot,4); %label the clusters in the region data = regionprops(label,'basic'); % data ontains properties of clusters in the region object =find([data.Area]==max([data.Area])) % object conatains the label of the cluster with max area robot_x = data(object).Centroid(1); %x coordinates of the bot robot_y = data(object).Centroid(2); % Algorithm for movement of robot if (ball_x > ball_x_prev) % the ball is returning to the bot % Do something if (robot_y > y_proj) % Do something else Etc.
  • 89. 89 Topics..  What is MATLAB ??  Basic Matrix Operations  Script Files and M-files  Some more Operations and Functions APPLICATIONS:  Plotting functions ..  Image Processing Basics ..  Robotics Applications ..  GUI Design and Programming
  • 90. 90 Graphical User Interface What is GUI: A graphical user interface (GUI) is a user interface built with graphical objects such as  Buttons  Text fields  Sliders  Menus If the GUI is designed well-designed, it should be intuitively obvious to the user how its components function.
  • 91. 91 Push ButtonsRadio Buttons Frames Checkbox Slider Edit text static textAxes
  • 92. 92 Graphical User Interface Guide Editor Property InspectorResult Figure