Professional Documents
Culture Documents
Application Software
Tool
Satish Chavan
Assistant Professor
Department of Electronics & Telecommunication
Don Bosco Institute of Technology, Kurla
References
Rudra Pratap, “Getting Started with MATLAB: A
Quick Introduction for Scientists and Engineers, ”
Oxford University Press, 2002.
Brain R. Hunt, Ronald L. Lipsman, Jonathan M.
Rosenberg, “A Guide to MATLAB for Beginners
and Experienced Users,” Cambridge University Press,
2001
Delores M. Etter, David C. Kuncicky, Doug Hull,
“Introduction to Matlab7,” Third Edition,
Pearson Education, 2006
www.mathworks.com
Interactive Access to
LINPACK/EISPACK
Trusted numeric and matrix
computation techniques
Extra Functions
s
• 2D graphics •Linear Algebra
ns Interface (Mex
•Data Analysis
• 3-D graphics
•Signal Processing •Files)
Interface with C
• Color & Lighting and Fortran Programs
• Animation •Polynomials & Interpolations
•Quadrature
•Solutions of ODEs
Help Browser
Current Directory Browse
Workspace Browser
Array Editor
Editor/Debugger
Profiler
Figure Window
July 28, 2010 Satish Chavan, DBIT 9
Command Window
Y label
browser.
lookfor -- Search all M-files for keyword.
information.
version -- MATLAB version information.
Addition + a + b
Subtraction - a - b
Assignment = a = b (assign b to a)
>> 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
» a=23
a=
23
» r = [12 , 14 , 63]
r=
12 14 63
» x = [1 , 2 , 3 ; 4 , 5 ,6 ; 7 , 8 , 9]
x=
1 2 3
4 5 6
7 8 9
July 28, 2010 Satish Chavan, DBIT 32
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 ) ;
x =
1 2 5 1
a matrix
y = [1 2 3; 5 1 4; 3 2 -1]
y =
1 2 3
5 1 4
3 2 -1
transpose p = x.’ p =
1
2
5
1
hist(x,100)
for
for i = 1:5
for j = 1:3
A(m, n) = 1/(i+j);
end
end
switch
n = 3;
switch n
case 1
disp('1')
case {2, 3, 4}
disp('2 or 3 or 4')
otherwise
disp('something else')
end
while
sum = 0;
n = -2;
while n <= 5
sum = sum + n;
n = n + 1;
end
sum
• The ‘while' loop executes statements repeatedly as long as the
controlling expression is true(1)
while expression
statements
end
July 28, 2010 Satish Chavan, DBIT 58
Generating Vectors from
functions
zeros(M,N) x = zeros(1,3)
MxN matrix of zeros x =
ones(M,N) 0 0 0
≫A = [1 2 3 4]; ma = avg(A)
≫B = [1 2; 3 4]; mb = avg(B)
Function name
• has the same constraints as variable name
• ONE function in ONE file
• file name > function name
• The name of the M-file and of the function SHOULD be the same
Questions Please…???