SlideShare a Scribd company logo
Introduction to Matlab on
Signal Processing
Dr. Monauwer Alam
Integral University Lucknow
Back Ground Of Matlab(Matrix
Laboratory)
Developed by Cleve Moler in the 1970s
MathWorks company founded in 1984 for commercial
development
The fundamental datatype is the matrix (array)
Arithmeticy stuff in Matlabmathematical notation is pretty standardized.
2+3 ans=5 Matlab assigns the most
recent calculation to ans…
a=34*8 a=272 unless you make an
assignment explicitly
b=a b=272
pi ans=3.1416 Common constants are
available…
i ans =0.0000 +
1.0000i
as are complex numbers.
sin(pi) ans=1.2246e-16 Should we worry this isn’t
zero?
Vectors in Matlab
d=[1 2 3 4 5 6] d = 1 2 3 4 5
6
d, e, and f are all
equivalent 1 x 6 vectors
e=[1:6] e = 1 2 3 4 5
6
f=1:6 f = 1 2 3 4 5
6
g = 0:2:6 g = 0 2 4 6
sin(g) ans = 0 0.9093
-0.7568 -0.2794
Matlab applies the sine
function to each element
of g.
g(3) 4
g(1:3) 0 2 4
g' ans = 0
2
4
6
Vector in Matlab
Matrices in Matlabh=[1 2 3; 4 5 6; 7 8 9] h =
1 2 3
4 5 6
7 8 9
h(2,2) ans =
5
Selecting the entry in the
second row second column.
h(2,:) ans =
4 5 6
Selecting the entries in the
second row but all columns.
h(:,2:3) ans =
2 3
5 6
8 9
Selecting the entries in the all
rows in columns 2-3.
h(3) ans =
7
With one index, Matlab counts
column-by-column.
h^2 ans =
30 36 42
66 81 96
102 126 150
This is matrix multiplication.
h.^2 ans =
1 4 9
16 25 36
49 64 81
With the period we get multiply
the elements of h by
themselves pointwise.
Matrix In Matlab
More MatricesMatlab has many functions for creating matrices.
rand(2,3) ans =
0.8147 0.1270
0.6324
0.9058 0.9134
0.0975
ones(2) ans =
1 1
1 1
This is the same as
ones(2,2)
zeros(1,4) ans =
0 0 0 0
This is the most common
way to initialize variables.
a=[1 2;3 4] a =
1 2
3 4
[a a] ans =
1 2 1 2
3 4 3 4
Horizontal concatenation
[a ; a] ans =
1 2
3 4
1 2
3 4
Vertical
A few useful notes
• The help command will display a function’s help text. The doc
command brings up more information
help sin
doc sin
• The semi-colon (;) will suppress output
• TThe percent sign is used for comments
%This is a Matlab comment
Some Useful Tips
Plotting curves in Matlab
It’s pretty straightforward
to plot one vector against
another in Matlab
x=-5:.1:5;
plot(sin(x))
here both x and sin(x) are
vectors of size 1 x 101.
Ploting
Plotting curves in Matlab
x=-5:.1:5;
plot(x,sin(x), 'g')
Ploting Curve in Matlab
PlottingPloting Curve in Matlab
curves in Matlab
subplot(1,2,1)
plot(x,sin(x),'g')
subplot(1,2,2)
plot(x,cos(x),'r-.')
Plotting surfaces in Matlab
Plotting surfaces in Matlab is
similar to plotting curves.
[x y]=meshgrid(-5:.1:5,-
5:.1:5);
z=x.^2-y.^2;
mesh(x,y,z)
Here x,y, and z are all
matrices of size 101 x 101.
Ploting Surfaces in Matlab

More Related Content

What's hot

Dynamic Programming
Dynamic ProgrammingDynamic Programming
Dynamic Programming
Sahil Kumar
 
Gaussian Elimination Method
Gaussian Elimination MethodGaussian Elimination Method
Gaussian Elimination Method
Andi Firdaus
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
Rajendran
 
Linear transformations and matrices
Linear transformations and matricesLinear transformations and matrices
Linear transformations and matrices
EasyStudy3
 
Applications of Linear Algebra in Computer Sciences
Applications of Linear Algebra in Computer SciencesApplications of Linear Algebra in Computer Sciences
Applications of Linear Algebra in Computer Sciences
Amir Sharif Chishti
 
String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)
Aditya pratap Singh
 
Euler's and picard's
Euler's and picard'sEuler's and picard's
Euler's and picard's
Manikanta satyala
 
Echelon and reduced echelon form & Filters
Echelon and reduced echelon form & FiltersEchelon and reduced echelon form & Filters
Echelon and reduced echelon form & Filters
Zahid Ali
 
Multiple Choice Questions - Numerical Methods
Multiple Choice Questions - Numerical MethodsMultiple Choice Questions - Numerical Methods
Multiple Choice Questions - Numerical Methods
Meenakshisundaram N
 
Merge sort algorithm
Merge sort algorithmMerge sort algorithm
Merge sort algorithm
Shubham Dwivedi
 
classification of second order partial differential equation
classification of second order partial differential equationclassification of second order partial differential equation
classification of second order partial differential equation
jigar methaniya
 
system linear equations and matrices
 system linear equations and matrices system linear equations and matrices
system linear equations and matrices
Aditya Vaishampayan
 
Trees
Trees Trees
Trees
Gaditek
 
Linear Algebra and Matlab tutorial
Linear Algebra and Matlab tutorialLinear Algebra and Matlab tutorial
Linear Algebra and Matlab tutorial
Jia-Bin Huang
 
context free language
context free languagecontext free language
context free language
khush_boo31
 

What's hot (20)

Dynamic Programming
Dynamic ProgrammingDynamic Programming
Dynamic Programming
 
Gaussian Elimination Method
Gaussian Elimination MethodGaussian Elimination Method
Gaussian Elimination Method
 
Recursion tree method
Recursion tree methodRecursion tree method
Recursion tree method
 
Numerical method
Numerical methodNumerical method
Numerical method
 
Np cooks theorem
Np cooks theoremNp cooks theorem
Np cooks theorem
 
Linear transformations and matrices
Linear transformations and matricesLinear transformations and matrices
Linear transformations and matrices
 
Applications of Linear Algebra in Computer Sciences
Applications of Linear Algebra in Computer SciencesApplications of Linear Algebra in Computer Sciences
Applications of Linear Algebra in Computer Sciences
 
String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)String Matching (Naive,Rabin-Karp,KMP)
String Matching (Naive,Rabin-Karp,KMP)
 
Gauss jordan
Gauss jordanGauss jordan
Gauss jordan
 
Euler's and picard's
Euler's and picard'sEuler's and picard's
Euler's and picard's
 
Unit vi
Unit viUnit vi
Unit vi
 
Echelon and reduced echelon form & Filters
Echelon and reduced echelon form & FiltersEchelon and reduced echelon form & Filters
Echelon and reduced echelon form & Filters
 
Recursion DM
Recursion DMRecursion DM
Recursion DM
 
Multiple Choice Questions - Numerical Methods
Multiple Choice Questions - Numerical MethodsMultiple Choice Questions - Numerical Methods
Multiple Choice Questions - Numerical Methods
 
Merge sort algorithm
Merge sort algorithmMerge sort algorithm
Merge sort algorithm
 
classification of second order partial differential equation
classification of second order partial differential equationclassification of second order partial differential equation
classification of second order partial differential equation
 
system linear equations and matrices
 system linear equations and matrices system linear equations and matrices
system linear equations and matrices
 
Trees
Trees Trees
Trees
 
Linear Algebra and Matlab tutorial
Linear Algebra and Matlab tutorialLinear Algebra and Matlab tutorial
Linear Algebra and Matlab tutorial
 
context free language
context free languagecontext free language
context free language
 

Similar to Matlab on basic mathematics

Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
krajeshk1980
 
Matlab-1.pptx
Matlab-1.pptxMatlab-1.pptx
Matlab-1.pptx
aboma2hawi
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
Vikash Jakhar
 
MATLAB Basics-Part1
MATLAB Basics-Part1MATLAB Basics-Part1
MATLAB Basics-Part1
Elaf A.Saeed
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
joellivz
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
Damian T. Gordon
 
Basic concepts in_matlab
Basic concepts in_matlabBasic concepts in_matlab
Basic concepts in_matlab
Mohammad Alauddin
 
Basic MATLAB-Presentation.pptx
Basic MATLAB-Presentation.pptxBasic MATLAB-Presentation.pptx
Basic MATLAB-Presentation.pptx
PremanandS3
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
Amr Rashed
 
Matlab intro
Matlab introMatlab intro
Matlab intro
Chaitanya Banoth
 
Matlab
MatlabMatlab
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
Satish Gummadi
 
Matlab
MatlabMatlab
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
Dnyanesh Patil
 
Fundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLABFundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLAB
Ali Ghanbarzadeh
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
raghav415187
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
Mukesh Kumar
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
Ravibabu Kancharla
 
Variables in matlab
Variables in matlabVariables in matlab
Variables in matlabTUOS-Sam
 

Similar to Matlab on basic mathematics (20)

Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
 
Matlab-1.pptx
Matlab-1.pptxMatlab-1.pptx
Matlab-1.pptx
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Matlab1
Matlab1Matlab1
Matlab1
 
MATLAB Basics-Part1
MATLAB Basics-Part1MATLAB Basics-Part1
MATLAB Basics-Part1
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functions
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
Basic concepts in_matlab
Basic concepts in_matlabBasic concepts in_matlab
Basic concepts in_matlab
 
Basic MATLAB-Presentation.pptx
Basic MATLAB-Presentation.pptxBasic MATLAB-Presentation.pptx
Basic MATLAB-Presentation.pptx
 
Introduction to Matlab
Introduction to MatlabIntroduction to Matlab
Introduction to Matlab
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 
Matlab
MatlabMatlab
Matlab
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Matlab
MatlabMatlab
Matlab
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
Fundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLABFundamentals of Image Processing & Computer Vision with MATLAB
Fundamentals of Image Processing & Computer Vision with MATLAB
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
 
A complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projectsA complete introduction on matlab and matlab's projects
A complete introduction on matlab and matlab's projects
 
Introduction to Matlab.ppt
Introduction to Matlab.pptIntroduction to Matlab.ppt
Introduction to Matlab.ppt
 
Variables in matlab
Variables in matlabVariables in matlab
Variables in matlab
 

Recently uploaded

The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
Vivekanand Anglo Vedic Academy
 
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
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
siemaillard
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
Tamralipta Mahavidyalaya
 
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
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
Thiyagu K
 
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
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Po-Chuan Chen
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
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
 
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
 
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
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Atul Kumar Singh
 
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
 
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
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
TechSoup
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Thiyagu K
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
Balvir Singh
 
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
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
DhatriParmar
 

Recently uploaded (20)

The French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free downloadThe French Revolution Class 9 Study Material pdf free download
The French Revolution Class 9 Study Material pdf free download
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
 
Home assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdfHome assignment II on Spectroscopy 2024 Answers.pdf
Home assignment II on Spectroscopy 2024 Answers.pdf
 
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
 
Unit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdfUnit 8 - Information and Communication Technology (Paper I).pdf
Unit 8 - Information and Communication Technology (Paper I).pdf
 
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
 
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdfAdversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
Adversarial Attention Modeling for Multi-dimensional Emotion Regression.pdf
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
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.
 
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.
 
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
 
Guidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th SemesterGuidance_and_Counselling.pdf B.Ed. 4th Semester
Guidance_and_Counselling.pdf B.Ed. 4th Semester
 
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
 
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...
 
Introduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp NetworkIntroduction to AI for Nonprofits with Tapp Network
Introduction to AI for Nonprofits with Tapp Network
 
Unit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdfUnit 2- Research Aptitude (UGC NET Paper I).pdf
Unit 2- Research Aptitude (UGC NET Paper I).pdf
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
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
 
The Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptxThe Accursed House by Émile Gaboriau.pptx
The Accursed House by Émile Gaboriau.pptx
 

Matlab on basic mathematics

  • 1. Introduction to Matlab on Signal Processing Dr. Monauwer Alam Integral University Lucknow
  • 2. Back Ground Of Matlab(Matrix Laboratory) Developed by Cleve Moler in the 1970s MathWorks company founded in 1984 for commercial development The fundamental datatype is the matrix (array)
  • 3. Arithmeticy stuff in Matlabmathematical notation is pretty standardized. 2+3 ans=5 Matlab assigns the most recent calculation to ans… a=34*8 a=272 unless you make an assignment explicitly b=a b=272 pi ans=3.1416 Common constants are available… i ans =0.0000 + 1.0000i as are complex numbers. sin(pi) ans=1.2246e-16 Should we worry this isn’t zero?
  • 4. Vectors in Matlab d=[1 2 3 4 5 6] d = 1 2 3 4 5 6 d, e, and f are all equivalent 1 x 6 vectors e=[1:6] e = 1 2 3 4 5 6 f=1:6 f = 1 2 3 4 5 6 g = 0:2:6 g = 0 2 4 6 sin(g) ans = 0 0.9093 -0.7568 -0.2794 Matlab applies the sine function to each element of g. g(3) 4 g(1:3) 0 2 4 g' ans = 0 2 4 6 Vector in Matlab
  • 5. Matrices in Matlabh=[1 2 3; 4 5 6; 7 8 9] h = 1 2 3 4 5 6 7 8 9 h(2,2) ans = 5 Selecting the entry in the second row second column. h(2,:) ans = 4 5 6 Selecting the entries in the second row but all columns. h(:,2:3) ans = 2 3 5 6 8 9 Selecting the entries in the all rows in columns 2-3. h(3) ans = 7 With one index, Matlab counts column-by-column. h^2 ans = 30 36 42 66 81 96 102 126 150 This is matrix multiplication. h.^2 ans = 1 4 9 16 25 36 49 64 81 With the period we get multiply the elements of h by themselves pointwise. Matrix In Matlab
  • 6. More MatricesMatlab has many functions for creating matrices. rand(2,3) ans = 0.8147 0.1270 0.6324 0.9058 0.9134 0.0975 ones(2) ans = 1 1 1 1 This is the same as ones(2,2) zeros(1,4) ans = 0 0 0 0 This is the most common way to initialize variables. a=[1 2;3 4] a = 1 2 3 4 [a a] ans = 1 2 1 2 3 4 3 4 Horizontal concatenation [a ; a] ans = 1 2 3 4 1 2 3 4 Vertical
  • 7. A few useful notes • The help command will display a function’s help text. The doc command brings up more information help sin doc sin • The semi-colon (;) will suppress output • TThe percent sign is used for comments %This is a Matlab comment Some Useful Tips
  • 8. Plotting curves in Matlab It’s pretty straightforward to plot one vector against another in Matlab x=-5:.1:5; plot(sin(x)) here both x and sin(x) are vectors of size 1 x 101. Ploting
  • 9. Plotting curves in Matlab x=-5:.1:5; plot(x,sin(x), 'g') Ploting Curve in Matlab
  • 10. PlottingPloting Curve in Matlab curves in Matlab subplot(1,2,1) plot(x,sin(x),'g') subplot(1,2,2) plot(x,cos(x),'r-.')
  • 11. Plotting surfaces in Matlab Plotting surfaces in Matlab is similar to plotting curves. [x y]=meshgrid(-5:.1:5,- 5:.1:5); z=x.^2-y.^2; mesh(x,y,z) Here x,y, and z are all matrices of size 101 x 101. Ploting Surfaces in Matlab