SlideShare a Scribd company logo
CIS 601 Fall 2003
Introduction to MATLAB
Longin Jan Latecki
Based on the lectures of Rolf Lakaemper and David Young
MATLAB
This introduction will give
• a brief overview, it’s not a MATLAB
tutorial !
• Some basic ideas
• Main advantages and drawbacks
compared to other languages
MATLAB
What Is MATLAB?
MATLAB (MATrix LABoratory)
• high-performance language for technical computing
• computation, visualization, and programming in an easy-to-
use environment
Typical uses include:
• Math and computation
• Algorithm development
• Modelling, simulation, and prototyping
• Data analysis, exploration, and visualization
• Scientific and engineering graphics
• Application development, including Graphical User Interface
building
Why MATLAB
A good choice for vision program development
because:
• Easy to do very rapid prototyping
• Quick to learn, and good documentation
• A good library of image processing functions
• Excellent display capabilities
• Widely used for teaching and research in
universities and industry
• Another language to impress your boss with !
Why not MATLAB
Has some drawbacks:
• Slow for some kinds of processes
• Not geared to the web
• Not designed for large-scale system
development
MATLAB Components
MATLAB consists of:
• The MATLAB language
• a high-level matrix/array language with control flow statements, functions,
data structures, input/output, and object-oriented programming features.
• The MATLAB working environment
• the set of tools and facilities that you work with as the MATLAB user or
programmer, including tools for developing, managing, debugging, and
profiling
• Handle Graphics
• the MATLAB graphics system. It includes high-level commands for two-
dimensional and three-dimensional data visualization, image processing,
animation, and presentation graphics.
• …(cont’d)
MATLAB Components
…
• The MATLAB function library.
• a vast collection of computational algorithms ranging from elementary
functions like sum, sine, cosine, and complex arithmetic, to more
sophisticated functions like matrix inverse, matrix eigenvalues, Bessel
functions, and fast Fourier transforms as well as special image processing
related functions
• The MATLAB Application Program Interface (API)
• a library that allows you to write C and Fortran programs that interact with
MATLAB. It include facilities for calling routines from MATLAB (dynamic
linking), calling MATLAB as a computational engine, and for reading and
writing MAT-files.
MATLAB
Some facts for a first impression
• Everything in MATLAB is a matrix !
• MATLAB is an interpreted language, no
compilation needed (but possible)
• MATLAB does not need any variable
declarations, no dimension statements, has no
packaging, no storage allocation, no pointers
• Programs can be run step by step, with full
access to all variables, functions etc.
What does Matlab code look like?
A simple example:
a = 1
while length(a) < 10
a = [0 a] + [a 0]
end which prints out Pascal’s triangle:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
1 5 10 10 5 1
1 6 15 20 15 6 1
1 7 21 35 35 21 7 1
1 8 28 56 70 56 28 8 1
1 9 36 84 126 126 84 36 9 1
(with “a=” before each line).
What does Matlab code look like?
Another simple example:
t = 0:pi/100:2*pi;
y = sin(t);
plot(t,y)
What does Matlab code look like?
Another simple example:
t = 0:pi/100:2*pi;
y = sin(t);
plot(t,y)
Remember:
EVERYTHING IN MATLAB
IS A MATRIX !
creates 1 x 200 Matrix
Argument and result: 1 x 200 Matrix
Matrices
Matrices
•Rows and columns are always numbered starting at 1
•Matlab matrices are of various types to hold different
kinds of data (usually floats or integers)
• A single number is really a 1 x 1 matrix in Matlab!
• Matlab variables are not given a type, and do not need
to be declared
• Any matrix can be assigned to any variable
Matrices
Building matrices with [ ]:
A = [2 7 4]
A = [2; 7; 4]
A = [2 7 4; 3 8 9]
B = [ A A ]
2 7 4
2
7
4
2 7 4
3 8 9
?
Matrices
Building matrices with [ ]:
A = [2 7 4]
A = [2; 7; 4]
A = [2 7 4; 3 8 9]
B = [ A A ]
2 7 4
2
7
4
2 7 4
3 8 9
2 7 4
3 8 9
2 7 4
3 8 9
Matrices
Matrices
Some operators must be handled with care:
A = [1 2 ; 4 5]
B = A * A prints 9 12
24 33
B = A .* A prints 1 4
16 25
Element by element multiplication
Submatrices
A matrix can be indexed using another matrix, to
produce a subset of its elements:
a = [100 200 300 400 500 600 700] b = [3 5 6]
c = a(b):
300 500 600
Submatrices
To get a subsection of a matrix, we can produce the
index matrix with the colon operator:
a(2:5)
prints
ans = 200 300 400 500
•This works in 2-D as well, e.g. c(2:3, 1:2) produces a
2 x 2 submatrix.
•The rows and columns of the submatrix are
renumbered.
loops
‘for’ loops in MATLAB iterate over matrix elements:
b = 0
for i = [ 3 9 17]
b = b + i;
end
Result: 29
Note:
The MATLAB way to write that program would have been:
b = sum([ 3 9 17]);
Avoid loops if possible !
loops
The typical ‘for’ loop looks like:
for i = 1:6
…
end
Which is the same as:
for i = [1 2 3 4 5 6]
…
end
loops
Once again:
AVOID LOOPS
Images
So why MATLAB and IMAGE
PROCESSING ?
Images
Images can be treated as
matrices !
Images
Loading an image:
a = imread(‘picture.jpg’);
imshow(a);
Images
Image (=matrix) size:
size(a): 384 512 3
R G B
384
512
Images
Color image:
3D Matrix of RGB planes
Images
Show RED plane:
a(:,:,2:3) = 0;
imshow(a);
Images
Show GREEN plane:
a(:,:,[1 3]) = 0;
imshow(a);
Images
Show BLUE plane:
a(:,:,1:2) = 0;
imshow(a);
Images
Advanced: Shuffling columns
rn = rand(1,512);
[rn1,i] = sort(rn);
b = a(:,i,:);
imshow(b);
Images
By the way…
MATLAB can also handle
• Movies
• 3D objects
• …
Conclusion
MATLAB is a mighty tool to
manipulate matrices
Images can be treated as
matrices
MATLAB is a mighty tool to
manipulate images
In my opinion…
MATLAB should be used to code
software prototypes
Research is mostly about
prototypes, not runtime-optimized
software
MATLAB should be used in
research
In my opinion…
•MATLAB prototypes must be re-
coded (e.g. in C++) if there’s need
for speed
•Algorithm development time is
drastically shorter in MATLAB
Image Algebra
A+B (matrix addition)
A-B
Examples:
http://www.ee.siue.edu/~cvip/CVIPtools_demos/mainframe.shtml
Matlab program: algebraEx.m
Quick Matlab overview
Homework:
Write a Matlab program that computes
a complement image to a given gray level image A

More Related Content

Similar to MATLAB_CIS601-03.ppt (20)

PDF
Image processing
Pooya Sagharchiha
 
PPTX
Basics of Matlab An Overview An Introductory Tutorial
ShaneMagnaye1
 
PPTX
MATLAB : Introduction , Features , Display Windows, Syntax, Operators, Graph...
Amity University, Patna
 
PPTX
Introduction to MATLAB
Ravikiran A
 
PPSX
Summer training introduction to matlab
Arshit Rai
 
PPT
MATLAB-tutorial for Image Processing with Lecture 3.ppt
ssuser5fb79d
 
PDF
Matlab pt1
Austin Baird
 
PPTX
MATLAB & Image Processing
Techbuddy Consulting Pvt. Ltd.
 
PPTX
From zero to MATLAB hero: Mastering the basics and beyond
MahuaPal6
 
PPT
Introduction_to_Matlabbanmar k ibrahim a
naghamsalimmohammed
 
PPT
MatlabIntro (1).ppt
AkashSingh728626
 
PDF
MATLAB_intro_lect1 details about matlab(1).pdf
juhishrivastava25
 
PDF
EE6711 Power System Simulation Lab manual
Velalar College of Engineering and Technology
 
PPTX
All About MATLAB
Multisoft Virtual Academy
 
PPTX
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
prashantkumarchinama
 
PPT
Matlab anilkumar
THEMASTERBLASTERSVID
 
PPT
Matlab practical and lab session
Dr. Krishna Mohbey
 
DOC
Matlab summary
Vinnu Vinay
 
PPT
Matlab introduction
Vikash Jakhar
 
PPTX
MATLAB'S PRESENTS1.pptx
NikhilPadole5
 
Image processing
Pooya Sagharchiha
 
Basics of Matlab An Overview An Introductory Tutorial
ShaneMagnaye1
 
MATLAB : Introduction , Features , Display Windows, Syntax, Operators, Graph...
Amity University, Patna
 
Introduction to MATLAB
Ravikiran A
 
Summer training introduction to matlab
Arshit Rai
 
MATLAB-tutorial for Image Processing with Lecture 3.ppt
ssuser5fb79d
 
Matlab pt1
Austin Baird
 
MATLAB & Image Processing
Techbuddy Consulting Pvt. Ltd.
 
From zero to MATLAB hero: Mastering the basics and beyond
MahuaPal6
 
Introduction_to_Matlabbanmar k ibrahim a
naghamsalimmohammed
 
MatlabIntro (1).ppt
AkashSingh728626
 
MATLAB_intro_lect1 details about matlab(1).pdf
juhishrivastava25
 
EE6711 Power System Simulation Lab manual
Velalar College of Engineering and Technology
 
All About MATLAB
Multisoft Virtual Academy
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
prashantkumarchinama
 
Matlab anilkumar
THEMASTERBLASTERSVID
 
Matlab practical and lab session
Dr. Krishna Mohbey
 
Matlab summary
Vinnu Vinay
 
Matlab introduction
Vikash Jakhar
 
MATLAB'S PRESENTS1.pptx
NikhilPadole5
 

More from aboma2hawi (14)

PPTX
Introduction_to_Matlab_lecture.pptx
aboma2hawi
 
PPTX
programming_tutorial_course_ lesson_1.pptx
aboma2hawi
 
PPTX
Matlab-3.pptx
aboma2hawi
 
PPT
matlab_tutorial.ppt
aboma2hawi
 
PPTX
Matlab-1.pptx
aboma2hawi
 
PPTX
HDP Module One (1).pptx
aboma2hawi
 
PPT
5_2019_01_12!09_25_57_AM.ppt
aboma2hawi
 
PDF
08822428
aboma2hawi
 
PDF
08764396
aboma2hawi
 
PDF
109 me0422
aboma2hawi
 
PDF
10.1.1.1039.4745
aboma2hawi
 
PDF
10.1.1.193.2962
aboma2hawi
 
PDF
Step response plot of dynamic system; step response data matlab step
aboma2hawi
 
PDF
Lab 4 matlab for controls state space analysis
aboma2hawi
 
Introduction_to_Matlab_lecture.pptx
aboma2hawi
 
programming_tutorial_course_ lesson_1.pptx
aboma2hawi
 
Matlab-3.pptx
aboma2hawi
 
matlab_tutorial.ppt
aboma2hawi
 
Matlab-1.pptx
aboma2hawi
 
HDP Module One (1).pptx
aboma2hawi
 
5_2019_01_12!09_25_57_AM.ppt
aboma2hawi
 
08822428
aboma2hawi
 
08764396
aboma2hawi
 
109 me0422
aboma2hawi
 
10.1.1.1039.4745
aboma2hawi
 
10.1.1.193.2962
aboma2hawi
 
Step response plot of dynamic system; step response data matlab step
aboma2hawi
 
Lab 4 matlab for controls state space analysis
aboma2hawi
 
Ad

Recently uploaded (20)

PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PDF
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
PDF
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
PPTX
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PDF
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
PPTX
THE TAME BIRD AND THE FREE BIRD.pptxxxxx
MarcChristianNicolas
 
PPTX
BANDHA (BANDAGES) PPT.pptx ayurveda shalya tantra
rakhan78619
 
PPTX
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
PDF
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
PDF
community health nursing question paper 2.pdf
Prince kumar
 
PDF
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
0725.WHITEPAPER-UNIQUEWAYSOFPROTOTYPINGANDUXNOW.pdf
Thomas GIRARD, MA, CDP
 
The dynastic history of the Chahmana.pdf
PrachiSontakke5
 
Cultivation practice of Litchi in Nepal.pptx
UmeshTimilsina1
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
Isharyanti-2025-Cross Language Communication in Indonesian Language
Neny Isharyanti
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
Generative AI: it's STILL not a robot (CIJ Summer 2025)
Paul Bradshaw
 
THE TAME BIRD AND THE FREE BIRD.pptxxxxx
MarcChristianNicolas
 
BANDHA (BANDAGES) PPT.pptx ayurveda shalya tantra
rakhan78619
 
ASRB NET 2023 PREVIOUS YEAR QUESTION PAPER GENETICS AND PLANT BREEDING BY SAT...
Krashi Coaching
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
community health nursing question paper 2.pdf
Prince kumar
 
IMP NAAC REFORMS 2024 - 10 Attributes.pdf
BHARTIWADEKAR
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PATIENT ASSIGNMENTS AND NURSING CARE RESPONSIBILITIES.pptx
PRADEEP ABOTHU
 
Ad

MATLAB_CIS601-03.ppt

  • 1. CIS 601 Fall 2003 Introduction to MATLAB Longin Jan Latecki Based on the lectures of Rolf Lakaemper and David Young
  • 2. MATLAB This introduction will give • a brief overview, it’s not a MATLAB tutorial ! • Some basic ideas • Main advantages and drawbacks compared to other languages
  • 3. MATLAB What Is MATLAB? MATLAB (MATrix LABoratory) • high-performance language for technical computing • computation, visualization, and programming in an easy-to- use environment Typical uses include: • Math and computation • Algorithm development • Modelling, simulation, and prototyping • Data analysis, exploration, and visualization • Scientific and engineering graphics • Application development, including Graphical User Interface building
  • 4. Why MATLAB A good choice for vision program development because: • Easy to do very rapid prototyping • Quick to learn, and good documentation • A good library of image processing functions • Excellent display capabilities • Widely used for teaching and research in universities and industry • Another language to impress your boss with !
  • 5. Why not MATLAB Has some drawbacks: • Slow for some kinds of processes • Not geared to the web • Not designed for large-scale system development
  • 6. MATLAB Components MATLAB consists of: • The MATLAB language • a high-level matrix/array language with control flow statements, functions, data structures, input/output, and object-oriented programming features. • The MATLAB working environment • the set of tools and facilities that you work with as the MATLAB user or programmer, including tools for developing, managing, debugging, and profiling • Handle Graphics • the MATLAB graphics system. It includes high-level commands for two- dimensional and three-dimensional data visualization, image processing, animation, and presentation graphics. • …(cont’d)
  • 7. MATLAB Components … • The MATLAB function library. • a vast collection of computational algorithms ranging from elementary functions like sum, sine, cosine, and complex arithmetic, to more sophisticated functions like matrix inverse, matrix eigenvalues, Bessel functions, and fast Fourier transforms as well as special image processing related functions • The MATLAB Application Program Interface (API) • a library that allows you to write C and Fortran programs that interact with MATLAB. It include facilities for calling routines from MATLAB (dynamic linking), calling MATLAB as a computational engine, and for reading and writing MAT-files.
  • 8. MATLAB Some facts for a first impression • Everything in MATLAB is a matrix ! • MATLAB is an interpreted language, no compilation needed (but possible) • MATLAB does not need any variable declarations, no dimension statements, has no packaging, no storage allocation, no pointers • Programs can be run step by step, with full access to all variables, functions etc.
  • 9. What does Matlab code look like? A simple example: a = 1 while length(a) < 10 a = [0 a] + [a 0] end which prints out Pascal’s triangle: 1 1 1 1 2 1 1 3 3 1 1 4 6 4 1 1 5 10 10 5 1 1 6 15 20 15 6 1 1 7 21 35 35 21 7 1 1 8 28 56 70 56 28 8 1 1 9 36 84 126 126 84 36 9 1 (with “a=” before each line).
  • 10. What does Matlab code look like? Another simple example: t = 0:pi/100:2*pi; y = sin(t); plot(t,y)
  • 11. What does Matlab code look like? Another simple example: t = 0:pi/100:2*pi; y = sin(t); plot(t,y) Remember: EVERYTHING IN MATLAB IS A MATRIX ! creates 1 x 200 Matrix Argument and result: 1 x 200 Matrix
  • 13. Matrices •Rows and columns are always numbered starting at 1 •Matlab matrices are of various types to hold different kinds of data (usually floats or integers) • A single number is really a 1 x 1 matrix in Matlab! • Matlab variables are not given a type, and do not need to be declared • Any matrix can be assigned to any variable
  • 14. Matrices Building matrices with [ ]: A = [2 7 4] A = [2; 7; 4] A = [2 7 4; 3 8 9] B = [ A A ] 2 7 4 2 7 4 2 7 4 3 8 9 ?
  • 15. Matrices Building matrices with [ ]: A = [2 7 4] A = [2; 7; 4] A = [2 7 4; 3 8 9] B = [ A A ] 2 7 4 2 7 4 2 7 4 3 8 9 2 7 4 3 8 9 2 7 4 3 8 9
  • 17. Matrices Some operators must be handled with care: A = [1 2 ; 4 5] B = A * A prints 9 12 24 33 B = A .* A prints 1 4 16 25 Element by element multiplication
  • 18. Submatrices A matrix can be indexed using another matrix, to produce a subset of its elements: a = [100 200 300 400 500 600 700] b = [3 5 6] c = a(b): 300 500 600
  • 19. Submatrices To get a subsection of a matrix, we can produce the index matrix with the colon operator: a(2:5) prints ans = 200 300 400 500 •This works in 2-D as well, e.g. c(2:3, 1:2) produces a 2 x 2 submatrix. •The rows and columns of the submatrix are renumbered.
  • 20. loops ‘for’ loops in MATLAB iterate over matrix elements: b = 0 for i = [ 3 9 17] b = b + i; end Result: 29 Note: The MATLAB way to write that program would have been: b = sum([ 3 9 17]); Avoid loops if possible !
  • 21. loops The typical ‘for’ loop looks like: for i = 1:6 … end Which is the same as: for i = [1 2 3 4 5 6] … end
  • 23. Images So why MATLAB and IMAGE PROCESSING ?
  • 24. Images Images can be treated as matrices !
  • 25. Images Loading an image: a = imread(‘picture.jpg’); imshow(a);
  • 26. Images Image (=matrix) size: size(a): 384 512 3 R G B 384 512
  • 29. Images Show GREEN plane: a(:,:,[1 3]) = 0; imshow(a);
  • 31. Images Advanced: Shuffling columns rn = rand(1,512); [rn1,i] = sort(rn); b = a(:,i,:); imshow(b);
  • 33. By the way… MATLAB can also handle • Movies • 3D objects • …
  • 34. Conclusion MATLAB is a mighty tool to manipulate matrices Images can be treated as matrices MATLAB is a mighty tool to manipulate images
  • 35. In my opinion… MATLAB should be used to code software prototypes Research is mostly about prototypes, not runtime-optimized software MATLAB should be used in research
  • 36. In my opinion… •MATLAB prototypes must be re- coded (e.g. in C++) if there’s need for speed •Algorithm development time is drastically shorter in MATLAB
  • 37. Image Algebra A+B (matrix addition) A-B Examples: http://www.ee.siue.edu/~cvip/CVIPtools_demos/mainframe.shtml Matlab program: algebraEx.m Quick Matlab overview Homework: Write a Matlab program that computes a complement image to a given gray level image A