SlideShare a Scribd company logo
Introduction to MATLAB
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

More Related Content

Similar to INTRODUCTION TO MATLAB for PG students.ppt

Summer training introduction to matlab
Summer training  introduction to matlabSummer training  introduction to matlab
Summer training introduction to matlab
Arshit Rai
 
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
MahuaPal6
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab sessionDr. Krishna Mohbey
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
Ravikiran A
 
Matlab pt1
Matlab pt1Matlab pt1
Matlab pt1
Austin Baird
 
All About MATLAB
All About MATLABAll About MATLAB
All About MATLAB
Multisoft Virtual Academy
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
AkashSingh728626
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
Vikash Jakhar
 
Matlab anilkumar
Matlab  anilkumarMatlab  anilkumar
Matlab anilkumar
THEMASTERBLASTERSVID
 
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptxMATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
MATLAB Workshop yugjjnhhasfhlhhlllhl.pptx
prashantkumarchinama
 
EE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manualEE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manual
Velalar College of Engineering and Technology
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
Ameen San
 
Summer training in matlab
Summer training in matlabSummer training in matlab
Summer training in matlab
Arshit Rai
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab
Arshit Rai
 
MATLAB'S PRESENTS1.pptx
MATLAB'S  PRESENTS1.pptxMATLAB'S  PRESENTS1.pptx
MATLAB'S PRESENTS1.pptx
NikhilPadole5
 
Matlab
MatlabMatlab
MATLAB Assignment Help
MATLAB Assignment HelpMATLAB Assignment Help
MATLAB Assignment Help
Essay Corp
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab
Arshit Rai
 

Similar to INTRODUCTION TO MATLAB for PG students.ppt (20)

Summer training introduction to matlab
Summer training  introduction to matlabSummer training  introduction to matlab
Summer training introduction to matlab
 
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
 
Matlab practical and lab session
Matlab practical and lab sessionMatlab practical and lab session
Matlab practical and lab session
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
MATLAB & Image Processing
MATLAB & Image ProcessingMATLAB & Image Processing
MATLAB & Image Processing
 
Matlab pt1
Matlab pt1Matlab pt1
Matlab pt1
 
All About MATLAB
All About MATLABAll About MATLAB
All About MATLAB
 
Matlab summary
Matlab summaryMatlab summary
Matlab summary
 
MatlabIntro (1).ppt
MatlabIntro (1).pptMatlabIntro (1).ppt
MatlabIntro (1).ppt
 
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
 
EE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manualEE6711 Power System Simulation Lab manual
EE6711 Power System Simulation Lab manual
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Summer training in matlab
Summer training in matlabSummer training in matlab
Summer training in matlab
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab
 
MATLAB'S PRESENTS1.pptx
MATLAB'S  PRESENTS1.pptxMATLAB'S  PRESENTS1.pptx
MATLAB'S PRESENTS1.pptx
 
Matlab
MatlabMatlab
Matlab
 
MATLAB Assignment Help
MATLAB Assignment HelpMATLAB Assignment Help
MATLAB Assignment Help
 
Summer training matlab
Summer training matlab Summer training matlab
Summer training matlab
 

More from Karthik537368

electrostatics_3.ppthkuhguiyoyoyohyoliyo8y
electrostatics_3.ppthkuhguiyoyoyohyoliyo8yelectrostatics_3.ppthkuhguiyoyoyohyoliyo8y
electrostatics_3.ppthkuhguiyoyoyohyoliyo8y
Karthik537368
 
2_current_electricity_1.pptnefipnipdannaffkn
2_current_electricity_1.pptnefipnipdannaffkn2_current_electricity_1.pptnefipnipdannaffkn
2_current_electricity_1.pptnefipnipdannaffkn
Karthik537368
 
2_current_electricity_1.pptcdasdDdDddddddD
2_current_electricity_1.pptcdasdDdDddddddD2_current_electricity_1.pptcdasdDdDddddddD
2_current_electricity_1.pptcdasdDdDddddddD
Karthik537368
 
2_current_electricity_2.pptADOFBAKJBFFFF
2_current_electricity_2.pptADOFBAKJBFFFF2_current_electricity_2.pptADOFBAKJBFFFF
2_current_electricity_2.pptADOFBAKJBFFFF
Karthik537368
 
Power point slides for momentum, Impullse conservation of memntum
Power point slides for momentum, Impullse conservation of memntumPower point slides for momentum, Impullse conservation of memntum
Power point slides for momentum, Impullse conservation of memntum
Karthik537368
 
Motion in One Dimension - Kinematics ppt
Motion in One Dimension - Kinematics pptMotion in One Dimension - Kinematics ppt
Motion in One Dimension - Kinematics ppt
Karthik537368
 
MATLAB - PRESENTATION for PG studentspdf
MATLAB - PRESENTATION for PG studentspdfMATLAB - PRESENTATION for PG studentspdf
MATLAB - PRESENTATION for PG studentspdf
Karthik537368
 

More from Karthik537368 (7)

electrostatics_3.ppthkuhguiyoyoyohyoliyo8y
electrostatics_3.ppthkuhguiyoyoyohyoliyo8yelectrostatics_3.ppthkuhguiyoyoyohyoliyo8y
electrostatics_3.ppthkuhguiyoyoyohyoliyo8y
 
2_current_electricity_1.pptnefipnipdannaffkn
2_current_electricity_1.pptnefipnipdannaffkn2_current_electricity_1.pptnefipnipdannaffkn
2_current_electricity_1.pptnefipnipdannaffkn
 
2_current_electricity_1.pptcdasdDdDddddddD
2_current_electricity_1.pptcdasdDdDddddddD2_current_electricity_1.pptcdasdDdDddddddD
2_current_electricity_1.pptcdasdDdDddddddD
 
2_current_electricity_2.pptADOFBAKJBFFFF
2_current_electricity_2.pptADOFBAKJBFFFF2_current_electricity_2.pptADOFBAKJBFFFF
2_current_electricity_2.pptADOFBAKJBFFFF
 
Power point slides for momentum, Impullse conservation of memntum
Power point slides for momentum, Impullse conservation of memntumPower point slides for momentum, Impullse conservation of memntum
Power point slides for momentum, Impullse conservation of memntum
 
Motion in One Dimension - Kinematics ppt
Motion in One Dimension - Kinematics pptMotion in One Dimension - Kinematics ppt
Motion in One Dimension - Kinematics ppt
 
MATLAB - PRESENTATION for PG studentspdf
MATLAB - PRESENTATION for PG studentspdfMATLAB - PRESENTATION for PG studentspdf
MATLAB - PRESENTATION for PG studentspdf
 

Recently uploaded

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
Jheel Barad
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
joachimlavalley1
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
beazzy04
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
Atul Kumar Singh
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
Sandy Millin
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
timhan337
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
MysoreMuleSoftMeetup
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
TechSoup
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
Celine George
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
Pavel ( NSTU)
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
Vikramjit Singh
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
GeoBlogs
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
EduSkills OECD
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
Levi Shapiro
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
Jisc
 

Recently uploaded (20)

Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Instructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptxInstructions for Submissions thorugh G- Classroom.pptx
Instructions for Submissions thorugh G- Classroom.pptx
 
Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.Biological Screening of Herbal Drugs in detailed.
Biological Screening of Herbal Drugs in detailed.
 
Additional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdfAdditional Benefits for Employee Website.pdf
Additional Benefits for Employee Website.pdf
 
Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345Sha'Carri Richardson Presentation 202345
Sha'Carri Richardson Presentation 202345
 
Language Across the Curriculm LAC B.Ed.
Language Across the  Curriculm LAC B.Ed.Language Across the  Curriculm LAC B.Ed.
Language Across the Curriculm LAC B.Ed.
 
2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...2024.06.01 Introducing a competency framework for languag learning materials ...
2024.06.01 Introducing a competency framework for languag learning materials ...
 
Honest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptxHonest Reviews of Tim Han LMA Course Program.pptx
Honest Reviews of Tim Han LMA Course Program.pptx
 
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
Mule 4.6 & Java 17 Upgrade | MuleSoft Mysore Meetup #46
 
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup   New Member Orientation and Q&A (May 2024).pdfWelcome to TechSoup   New Member Orientation and Q&A (May 2024).pdf
Welcome to TechSoup New Member Orientation and Q&A (May 2024).pdf
 
How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17How to Make a Field invisible in Odoo 17
How to Make a Field invisible in Odoo 17
 
Chapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptxChapter 3 - Islamic Banking Products and Services.pptx
Chapter 3 - Islamic Banking Products and Services.pptx
 
Synthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptxSynthetic Fiber Construction in lab .pptx
Synthetic Fiber Construction in lab .pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Digital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and ResearchDigital Tools and AI for Teaching Learning and Research
Digital Tools and AI for Teaching Learning and Research
 
The geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideasThe geography of Taylor Swift - some ideas
The geography of Taylor Swift - some ideas
 
Francesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptxFrancesca Gottschalk - How can education support child empowerment.pptx
Francesca Gottschalk - How can education support child empowerment.pptx
 
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
June 3, 2024 Anti-Semitism Letter Sent to MIT President Kornbluth and MIT Cor...
 
How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...How libraries can support authors with open access requirements for UKRI fund...
How libraries can support authors with open access requirements for UKRI fund...
 

INTRODUCTION TO MATLAB for PG students.ppt

  • 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