Martin Ellison
University of Warwick and CEPR
Bank of England, December 2005
Introduction to
MATLAB
What is MATLAB?
MATLAB is a tool for doing numerical
computations with matrices and vectors. It is very
powerful and easy to use. It integrates
computation, graphics and programming in the
same environment.
MATLAB stands for “Matrix Laboratory”.
Matrix
MATLAB works with essentially only one kind
of object – a rectangular numerical matrix with
possible complex entries.
Entering a matrix
Matrices can be
Entered manually
Generated by built-in functions
An example
A = [1, 2, 3; 7, 8, 9]
Use ; to indicate the end of each row
Use comma to separate elements of a row
Matrix operations
+ addition
- subtraction
* multiplication
^ power
‘ transpose
To make * and ^ operate element-by-element,
we write .* and .^
Example
A= [1, 2; 3, 4]
B = [0.5, 0.6; 1, 1.5]
C = A*B
C = A.*B
Subscripts
The element in row i and column j of A is
denoted by A(i, j).
Example: A = zeros(2,2);
A(1,1) + A(1,2) + A(2,2)
The colon operator
The colon : is one of MATLAB ’s most
important operators. It has many uses.
3:-2:-11 is a row vector containing integers
from 3 to -11 with a increment of -2.
Subscript expressions involving colons refer to
portions of a matrix. A(1:3, 2) is the first to the
third elements of the second column of A.
Working with matrices
MATLAB provides four functions that generate
basic matrices.
zeros: all zeros. A = zeros(1,3)
ones: all ones. A = ones(2,4)
rand: uniformly distributed random
numbers. A = rand(3,5)
randn: normally distributed random
numbers. A = randn(2,2)
Working with matrices
Concatenation: join small (compatible) matrices
to make bigger ones. B = [A A-2; A*2 A/4]
Deleting rows and columns. B(:,2) = [ ]
Functions
MATLAB provides a large range of standard
elementary mathematical functions, including abs,
sqrt, exp, and sin.
For help on functions, type
help elfun (elementary mathematical functions)
help specfun (advanced mathematical functions)
help elmat (advanced matrix functions)
help datafun (data analysis functions)
Suppressing output
If you simply type a statement and press Enter,
MATLAB automatically displays the results on
screen. If you end the line with a semicolon ;
MATLAB performs the computation but does
not display any result.
Example: C = randn(5,1)
C = randn(5,1);
Programming with MATLAB
Files that contain code in the MATLAB
language are called M-files. You create M-files
using a text editor, then use them as you would
any other MATLAB functions or command.
Flow Control
MATLAB has many flow controls. The most
basic are
if statement
for loops
while loops
if … elseif … else … end
if A > B
‘greater’
elseif A < B
‘less’
elseif A = = B
‘equal’
end
for … end
for i = 1:m
for j = 1:n
H(i,j) = 1/(i+j)
end
end
while … end
i = 0;
while (i<10000)
s = s + i;
i = i + 1;
end
Graphics
x = 0 : 0.01 : 100;
y = x^2;
plot(x,y)
Adding plots to an existing graph: hold on
Multiple plots in one figure: subplot

More Related Content

PPT
MatlabIntro1234.ppt.....................
PDF
An Introduction to MATLAB with Worked Examples
PPTX
MATLAB : Introduction , Features , Display Windows, Syntax, Operators, Graph...
PPT
Matlab_Introduction_by_Michael_Medvinsky.ppt
PPT
MatlabIntroduction presentation xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
PPT
Matlab Introduction for beginners_i .ppt
PPT
Introduction to Matlab - Basic Functions
MatlabIntro1234.ppt.....................
An Introduction to MATLAB with Worked Examples
MATLAB : Introduction , Features , Display Windows, Syntax, Operators, Graph...
Matlab_Introduction_by_Michael_Medvinsky.ppt
MatlabIntroduction presentation xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Matlab Introduction for beginners_i .ppt
Introduction to Matlab - Basic Functions

Similar to introduction of matlab programming with example (20)

PPT
WIDI ediot autis dongok part 2.ediot lu lembot lu
PPT
WIDI ediot autis dongok part 3.EDIOT LU LEMBOT LY
PDF
A complete introduction on matlab and matlab's projects
PPT
Matlab practical and lab session
PPT
MatlabIntro.ppt
PPT
MatlabIntro.ppt
PPT
MatlabIntro.ppt
PPT
MatlabIntro.ppt
PPT
Matlab intro
PPT
WIDI ediot autis dongok part 1.ediot lu lemot lu setan lu
PPT
WIDI FREAK MANUSIA SETENGAH EDIOTDAN LEMBOT
PDF
PPTX
1. Introduction.pptx
DOC
Matlab tut2
DOC
Matlab summary
DOCX
MATLAB guide
PDF
MATLAB Programming
PPT
Matlab introduction
PPT
MATLAB-Introd.ppt
PDF
Introduction to MATLAB
WIDI ediot autis dongok part 2.ediot lu lembot lu
WIDI ediot autis dongok part 3.EDIOT LU LEMBOT LY
A complete introduction on matlab and matlab's projects
Matlab practical and lab session
MatlabIntro.ppt
MatlabIntro.ppt
MatlabIntro.ppt
MatlabIntro.ppt
Matlab intro
WIDI ediot autis dongok part 1.ediot lu lemot lu setan lu
WIDI FREAK MANUSIA SETENGAH EDIOTDAN LEMBOT
1. Introduction.pptx
Matlab tut2
Matlab summary
MATLAB guide
MATLAB Programming
Matlab introduction
MATLAB-Introd.ppt
Introduction to MATLAB
Ad

More from vishalkumarpandey12 (9)

PPTX
machine lessons to be taught for better concept
PPTX
the given concepts to be taught and explain
PPTX
presentation is created for Computer Vision
PPTX
presentation is created for mind subject
PPT
matlab tutorial with separate function description and handson learning
PPT
introduction to MATLAB with functions and plots
PPT
bipolar junction transistor basics with plot
PPTX
PO-CO SAMPLE QUESTIONS - DIP.pptx
PPT
Chapter10.ppt
machine lessons to be taught for better concept
the given concepts to be taught and explain
presentation is created for Computer Vision
presentation is created for mind subject
matlab tutorial with separate function description and handson learning
introduction to MATLAB with functions and plots
bipolar junction transistor basics with plot
PO-CO SAMPLE QUESTIONS - DIP.pptx
Chapter10.ppt
Ad

Recently uploaded (20)

PPTX
Soft Skills Unit 2 Listening Speaking Reading Writing.pptx
PDF
MACCAFERRY GUIA GAVIONES TERRAPLENES EN ESPAÑOL
DOCX
An investigation of the use of recycled crumb rubber as a partial replacement...
PPT
Programmable Logic Controller PLC and Industrial Automation
PPTX
INTERNET OF THINGS - EMBEDDED SYSTEMS AND INTERNET OF THINGS
PPTX
Solar energy pdf of gitam songa hemant k
PDF
Lesson 3 .pdf
PPT
UNIT-I Machine Learning Essentials for 2nd years
PPTX
Agentic Artificial Intelligence (Agentic AI).pptx
PDF
LS-6-Digital-Literacy (1) K12 CURRICULUM .pdf
PDF
electrical machines course file-anna university
DOCX
ENVIRONMENTAL PROTECTION AND MANAGEMENT (18CVL756)
PPTX
Unit IImachinemachinetoolopeartions.pptx
PDF
Using Technology to Foster Innovative Teaching Practices (www.kiu.ac.ug)
PDF
IAE-V2500 Engine Airbus Family A319/320
PDF
Engineering Solutions for Ethical Dilemmas in Healthcare (www.kiu.ac.ug)
PDF
CELDAS DE COMBUSTIBLE TIPO MEMBRANA DE INTERCAMBIO PROTÓNICO.pdf
PDF
Performance, energy consumption and costs: a comparative analysis of automati...
PPTX
CS6006 - CLOUD COMPUTING - Module - 1.pptx
PPTX
22ME926Introduction to Business Intelligence and Analytics, Advanced Integrat...
Soft Skills Unit 2 Listening Speaking Reading Writing.pptx
MACCAFERRY GUIA GAVIONES TERRAPLENES EN ESPAÑOL
An investigation of the use of recycled crumb rubber as a partial replacement...
Programmable Logic Controller PLC and Industrial Automation
INTERNET OF THINGS - EMBEDDED SYSTEMS AND INTERNET OF THINGS
Solar energy pdf of gitam songa hemant k
Lesson 3 .pdf
UNIT-I Machine Learning Essentials for 2nd years
Agentic Artificial Intelligence (Agentic AI).pptx
LS-6-Digital-Literacy (1) K12 CURRICULUM .pdf
electrical machines course file-anna university
ENVIRONMENTAL PROTECTION AND MANAGEMENT (18CVL756)
Unit IImachinemachinetoolopeartions.pptx
Using Technology to Foster Innovative Teaching Practices (www.kiu.ac.ug)
IAE-V2500 Engine Airbus Family A319/320
Engineering Solutions for Ethical Dilemmas in Healthcare (www.kiu.ac.ug)
CELDAS DE COMBUSTIBLE TIPO MEMBRANA DE INTERCAMBIO PROTÓNICO.pdf
Performance, energy consumption and costs: a comparative analysis of automati...
CS6006 - CLOUD COMPUTING - Module - 1.pptx
22ME926Introduction to Business Intelligence and Analytics, Advanced Integrat...

introduction of matlab programming with example

  • 1. Martin Ellison University of Warwick and CEPR Bank of England, December 2005 Introduction to MATLAB
  • 2. What is MATLAB? MATLAB is a tool for doing numerical computations with matrices and vectors. It is very powerful and easy to use. It integrates computation, graphics and programming in the same environment. MATLAB stands for “Matrix Laboratory”.
  • 3. Matrix MATLAB works with essentially only one kind of object – a rectangular numerical matrix with possible complex entries.
  • 4. Entering a matrix Matrices can be Entered manually Generated by built-in functions
  • 5. An example A = [1, 2, 3; 7, 8, 9] Use ; to indicate the end of each row Use comma to separate elements of a row
  • 6. Matrix operations + addition - subtraction * multiplication ^ power ‘ transpose To make * and ^ operate element-by-element, we write .* and .^
  • 7. Example A= [1, 2; 3, 4] B = [0.5, 0.6; 1, 1.5] C = A*B C = A.*B
  • 8. Subscripts The element in row i and column j of A is denoted by A(i, j). Example: A = zeros(2,2); A(1,1) + A(1,2) + A(2,2)
  • 9. The colon operator The colon : is one of MATLAB ’s most important operators. It has many uses. 3:-2:-11 is a row vector containing integers from 3 to -11 with a increment of -2. Subscript expressions involving colons refer to portions of a matrix. A(1:3, 2) is the first to the third elements of the second column of A.
  • 10. Working with matrices MATLAB provides four functions that generate basic matrices. zeros: all zeros. A = zeros(1,3) ones: all ones. A = ones(2,4) rand: uniformly distributed random numbers. A = rand(3,5) randn: normally distributed random numbers. A = randn(2,2)
  • 11. Working with matrices Concatenation: join small (compatible) matrices to make bigger ones. B = [A A-2; A*2 A/4] Deleting rows and columns. B(:,2) = [ ]
  • 12. Functions MATLAB provides a large range of standard elementary mathematical functions, including abs, sqrt, exp, and sin. For help on functions, type help elfun (elementary mathematical functions) help specfun (advanced mathematical functions) help elmat (advanced matrix functions) help datafun (data analysis functions)
  • 13. Suppressing output If you simply type a statement and press Enter, MATLAB automatically displays the results on screen. If you end the line with a semicolon ; MATLAB performs the computation but does not display any result. Example: C = randn(5,1) C = randn(5,1);
  • 14. Programming with MATLAB Files that contain code in the MATLAB language are called M-files. You create M-files using a text editor, then use them as you would any other MATLAB functions or command.
  • 15. Flow Control MATLAB has many flow controls. The most basic are if statement for loops while loops
  • 16. if … elseif … else … end if A > B ‘greater’ elseif A < B ‘less’ elseif A = = B ‘equal’ end
  • 17. for … end for i = 1:m for j = 1:n H(i,j) = 1/(i+j) end end
  • 18. while … end i = 0; while (i<10000) s = s + i; i = i + 1; end
  • 19. Graphics x = 0 : 0.01 : 100; y = x^2; plot(x,y) Adding plots to an existing graph: hold on Multiple plots in one figure: subplot