SlideShare a Scribd company logo
1 of 16
Download to read offline
MATRICES IN MATLAB
Ritesh Kumar
Defining matrices in MATLAB
� 1D row vector – [1 2 3 4] or [1,2,3,4]
� 1D column vector – [1;2;3;4]
� 2D matrix – [1 2 3; 4 5 6; 7 8 9]
� Make a 1D row vector from 1 to 100. Tired ?
Use this – [1:1:100] or [1:100].
Try changing the step size.
� ‘:’ means ‘to’
Using Colon (:)
� [1:4] gives a row vector containing [1 2 3 4]
� [1:0.5:4] gives a row vector from 1 to 4 with a
step size of 0.5
� Make a vector from 0 to 2π with a step size of
0.01
Matrix operators
� Normal operations
� A + B
� A – B
� A*B
� A^2
� Dot (.) operations: Element wise operations
� Y = A.^2
� Y = A.*B
� Y = A.^B
Predefined functions for Matrices
� Mathematical
�sin, cos, tan
�log, exp
�sqrt
� Creation
�ones
�zeros
�eye
�rand
� Information
�size
�length
Predefined functions for Matrices
� Matrix operations
� sum
� diag
� transpose or ‘
� inv
� det
� eig
� fliplr
� reshape
� flipud
� rot90
� repmat
Matrix concatenation
Suppose A, B, C are matrices
� If we write [A B] or [A,B]
� If we write [A;B]
� Similarly [A B C] and [A;B;C]
� [[A B];C]
Exercise
� Create a vector of 20 elements in GP with first
term 1 and common ratio ½. Calculate its sum
� Calculate the sum of first 15 elements of the
series
Indexing
� Extracting elements from the arrays
� Normal Indexing
� Linear Indexing
� Logical Indexing
Array indices
� A is an n×m matrix
� To extract the 5th row 6th column element
we’ll write A(5,6)
� The difference between Y=A(5,6) and
A(5,6)=Y
� Y=A(5,6) will extract the 5,6 element from A and
save it to Y
� A(5,6)=Y will change the 5,6 element to Y
Array indices
� What if we wish to extract multiple columns or
rows?
� A([1 3 7],[1 2])
� Gives a sub-matrix containing elements which were in
1,3 and 7th row and 1 and 2 columns of matrix A
� A([3 2 7],[3 2 3])
� A(:,[5 6])
� Here : means all
� Gives a sub-matrix containing all rows and 5 and 6
columns of matrix A
Linear Indexing
� A is 2D but we can use a single index to
extract any element from A
� A(5)
� Same as A(2,2)
A= 2 3 2
3 1 2
6 9 10
Exercise
� Extract a diagonal of a square 5x5 matrix
using linear indexing without using inbuilt
command.
Logical indexing
� Index with a matrix of 0 & 1
� Return those elements which corresponds to 1
� B=A>0;
� C=A(B);
Exercise
� Create a random matrix of 1x100. Change the
elements to 0 which are smaller than 0.33 and
1 which are greater than 0.33 and smaller than
0.67 and 2 which are greater than 0.67
Exercise
� A=[1 2 0 6 4 0 2];
� Get a B vector such that B=[1 ½ 0 1/6 ¼ 0 ½],
i.e. reverse the elements which are not 0

More Related Content

Similar to Basics of Matlab for students and faculty

COMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptxCOMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptximman gwu
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxDevaraj Chilakala
 
sparse matrices in tress
sparse matrices in tresssparse matrices in tress
sparse matrices in tresspavialone
 
Notes on MATLAB - Basic Cheatsheet
Notes on MATLAB    -    Basic CheatsheetNotes on MATLAB    -    Basic Cheatsheet
Notes on MATLAB - Basic CheatsheetAhmed Nassar
 
2.Exploration with CAS-I.Lab2.pptx
2.Exploration with CAS-I.Lab2.pptx2.Exploration with CAS-I.Lab2.pptx
2.Exploration with CAS-I.Lab2.pptxakshatraj875
 
Introduction to Matlab - Basic Functions
Introduction to Matlab - Basic FunctionsIntroduction to Matlab - Basic Functions
Introduction to Matlab - Basic Functionsjoellivz
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programmingDamian T. Gordon
 
Matlab level 1.pptx
Matlab level 1.pptxMatlab level 1.pptx
Matlab level 1.pptxAbanobGozef
 
MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.pptkebeAman
 

Similar to Basics of Matlab for students and faculty (20)

Mat lab
Mat labMat lab
Mat lab
 
COMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptxCOMPANION TO MATRICES SESSION II.pptx
COMPANION TO MATRICES SESSION II.pptx
 
Matlab
MatlabMatlab
Matlab
 
MATLAB ARRAYS
MATLAB ARRAYSMATLAB ARRAYS
MATLAB ARRAYS
 
INTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptxINTRODUCTION TO MATLAB presentation.pptx
INTRODUCTION TO MATLAB presentation.pptx
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
 
MATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesMATLAB - Arrays and Matrices
MATLAB - Arrays and Matrices
 
Basic concepts in_matlab
Basic concepts in_matlabBasic concepts in_matlab
Basic concepts in_matlab
 
sparse matrices in tress
sparse matrices in tresssparse matrices in tress
sparse matrices in tress
 
Mat lab day 1
Mat lab day 1Mat lab day 1
Mat lab day 1
 
Notes on MATLAB - Basic Cheatsheet
Notes on MATLAB    -    Basic CheatsheetNotes on MATLAB    -    Basic Cheatsheet
Notes on MATLAB - Basic Cheatsheet
 
bobok
bobokbobok
bobok
 
2.Exploration with CAS-I.Lab2.pptx
2.Exploration with CAS-I.Lab2.pptx2.Exploration with CAS-I.Lab2.pptx
2.Exploration with CAS-I.Lab2.pptx
 
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
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
 
Matlab level 1.pptx
Matlab level 1.pptxMatlab level 1.pptx
Matlab level 1.pptx
 
EPE821_Lecture3.pptx
EPE821_Lecture3.pptxEPE821_Lecture3.pptx
EPE821_Lecture3.pptx
 
R Programming Intro
R Programming IntroR Programming Intro
R Programming Intro
 
MATLAB-Introd.ppt
MATLAB-Introd.pptMATLAB-Introd.ppt
MATLAB-Introd.ppt
 

Recently uploaded

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Dr.Costas Sachpazis
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxupamatechverse
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)Suman Mia
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...Call Girls in Nagpur High Profile
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )Tsuyoshi Horigome
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxwendy cai
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024Mark Billinghurst
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130Suhani Kapoor
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxpranjaldaimarysona
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).pptssuser5c9d4b1
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 

Recently uploaded (20)

Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
Sheet Pile Wall Design and Construction: A Practical Guide for Civil Engineer...
 
Introduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptxIntroduction to IEEE STANDARDS and its different types.pptx
Introduction to IEEE STANDARDS and its different types.pptx
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)Software Development Life Cycle By  Team Orange (Dept. of Pharmacy)
Software Development Life Cycle By Team Orange (Dept. of Pharmacy)
 
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
High Profile Call Girls Nashik Megha 7001305949 Independent Escort Service Na...
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINEDJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
DJARUM4D - SLOT GACOR ONLINE | SLOT DEMO ONLINE
 
SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )SPICE PARK APR2024 ( 6,793 SPICE Models )
SPICE PARK APR2024 ( 6,793 SPICE Models )
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANVI) Koregaon Park Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
What are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptxWhat are the advantages and disadvantages of membrane structures.pptx
What are the advantages and disadvantages of membrane structures.pptx
 
IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024IVE Industry Focused Event - Defence Sector 2024
IVE Industry Focused Event - Defence Sector 2024
 
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
VIP Call Girls Service Kondapur Hyderabad Call +91-8250192130
 
Processing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptxProcessing & Properties of Floor and Wall Tiles.pptx
Processing & Properties of Floor and Wall Tiles.pptx
 
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
247267395-1-Symmetric-and-distributed-shared-memory-architectures-ppt (1).ppt
 
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur EscortsCall Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
Call Girls Service Nagpur Tanvi Call 7001035870 Meet With Nagpur Escorts
 

Basics of Matlab for students and faculty

  • 2. Defining matrices in MATLAB � 1D row vector – [1 2 3 4] or [1,2,3,4] � 1D column vector – [1;2;3;4] � 2D matrix – [1 2 3; 4 5 6; 7 8 9] � Make a 1D row vector from 1 to 100. Tired ? Use this – [1:1:100] or [1:100]. Try changing the step size. � ‘:’ means ‘to’
  • 3. Using Colon (:) � [1:4] gives a row vector containing [1 2 3 4] � [1:0.5:4] gives a row vector from 1 to 4 with a step size of 0.5 � Make a vector from 0 to 2π with a step size of 0.01
  • 4. Matrix operators � Normal operations � A + B � A – B � A*B � A^2 � Dot (.) operations: Element wise operations � Y = A.^2 � Y = A.*B � Y = A.^B
  • 5. Predefined functions for Matrices � Mathematical �sin, cos, tan �log, exp �sqrt � Creation �ones �zeros �eye �rand � Information �size �length
  • 6. Predefined functions for Matrices � Matrix operations � sum � diag � transpose or ‘ � inv � det � eig � fliplr � reshape � flipud � rot90 � repmat
  • 7. Matrix concatenation Suppose A, B, C are matrices � If we write [A B] or [A,B] � If we write [A;B] � Similarly [A B C] and [A;B;C] � [[A B];C]
  • 8. Exercise � Create a vector of 20 elements in GP with first term 1 and common ratio ½. Calculate its sum � Calculate the sum of first 15 elements of the series
  • 9. Indexing � Extracting elements from the arrays � Normal Indexing � Linear Indexing � Logical Indexing
  • 10. Array indices � A is an n×m matrix � To extract the 5th row 6th column element we’ll write A(5,6) � The difference between Y=A(5,6) and A(5,6)=Y � Y=A(5,6) will extract the 5,6 element from A and save it to Y � A(5,6)=Y will change the 5,6 element to Y
  • 11. Array indices � What if we wish to extract multiple columns or rows? � A([1 3 7],[1 2]) � Gives a sub-matrix containing elements which were in 1,3 and 7th row and 1 and 2 columns of matrix A � A([3 2 7],[3 2 3]) � A(:,[5 6]) � Here : means all � Gives a sub-matrix containing all rows and 5 and 6 columns of matrix A
  • 12. Linear Indexing � A is 2D but we can use a single index to extract any element from A � A(5) � Same as A(2,2) A= 2 3 2 3 1 2 6 9 10
  • 13. Exercise � Extract a diagonal of a square 5x5 matrix using linear indexing without using inbuilt command.
  • 14. Logical indexing � Index with a matrix of 0 & 1 � Return those elements which corresponds to 1 � B=A>0; � C=A(B);
  • 15. Exercise � Create a random matrix of 1x100. Change the elements to 0 which are smaller than 0.33 and 1 which are greater than 0.33 and smaller than 0.67 and 2 which are greater than 0.67
  • 16. Exercise � A=[1 2 0 6 4 0 2]; � Get a B vector such that B=[1 ½ 0 1/6 ¼ 0 ½], i.e. reverse the elements which are not 0