SlideShare a Scribd company logo
http://www.tutorialspoint.com/matlab/matlab_matrics.htm Copyright © tutorialspoint.com
MATLAB - MATRIX
A matrix is a two-dimensionalarray of numbers.
InMATLAB, youcreate a matrix by entering elements ineachrow as comma or space delimited numbers and
using semicolons to mark the end of eachrow.
For example, let us create a 4-by-5 matrix a:
a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8]
MATLAB willexecute the above statement and returnthe following result:
a =
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
4 5 6 7 8
Referencing the Elements of a Matrix
To reference anelement inthe mth row and nth column, of a matrix mx, we write:
mx(m, n);
For example, to refer to the element inthe 2nd row and 5th column, of the matrix a, as created inthe last section,
we type:
a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
a(2,5)
MATLAB willexecute the above statement and returnthe following result:
ans =
6
To reference allthe elements inthe mth columnwe type A(:,m).
Let us create a columnvector v, fromthe elements of the 4th row of the matrix a:
a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
v = a(:,4)
MATLAB willexecute the above statement and returnthe following result:
v =
4
5
6
7
Youcanalso select the elements inthe mth throughnth columns, for this we write:
a(:,m:n)
Let us create a smaller matrix taking the elements fromthe second and third columns:
a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
a(:, 2:3)
MATLAB willexecute the above statement and returnthe following result:
ans =
2 3
3 4
4 5
5 6
Inthe same way, youcancreate a sub-matrix taking a sub-part of a matrix.
a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
a(:, 2:3)
MATLAB willexecute the above statement and returnthe following result:
ans =
2 3
3 4
4 5
5 6
Inthe same way, youcancreate a sub-matrix taking a sub-part of a matrix.
For example, let us create a sub-matrix sa taking the inner subpart of a:
3 4 5
4 5 6
To do this, write:
a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
sa = a(2:3,2:4)
MATLAB willexecute the above statement and returnthe following result:
sa =
3 4 5
4 5 6
Deleting a Row or a Column in a Matrix
Youcandelete anentire row or columnof a matrix by assigning anempty set of square braces [] to that row or
column. Basically, [] denotes anempty array.
For example, let us delete the fourthrow of a:
a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
a( 4 , : ) = []
MATLAB willexecute the above statement and returnthe following result:
a =
1 2 3 4 5
2 3 4 5 6
3 4 5 6 7
Next, let us delete the fifthcolumnof a:
a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
a(: , 5)=[]
MATLAB willexecute the above statement and returnthe following result:
a =
1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7
Example
Inthis example, let us create a 3-by-3 matrix m, thenwe willcopy the second and third rows of this matrix twice to
create a 4-by-3 matrix.
Create a script file withthe following code:
a = [ 1 2 3 ; 4 5 6; 7 8 9];
new_mat = a([2,3,2,3],:)
Whenyourunthe file, it displays the following result:
new_mat =
4 5 6
7 8 9
4 5 6
7 8 9
Matrix Operations
Inthis section, let us discuss the following basic and commonly used matrix operations:
Additionand Subtractionof Matrices
Divisionof Matrices
Scalar Operations of Matrices
Transpose of a Matrix
Concatenating Matrices
Matrix Multiplication
Determinant of a Matrix
Inverse of a Matrix

More Related Content

PDF
Matlab lecture 9 – simpson 1,3 and trapezoidal method@taj
PDF
Soft computing lab
PPTX
Introduction to programming in MATLAB
PDF
Matlab variables
PPTX
Lecture two
PPT
Matlab final year project in jalandhar
PPT
Matlab final year project in ludhiana
Matlab lecture 9 – simpson 1,3 and trapezoidal method@taj
Soft computing lab
Introduction to programming in MATLAB
Matlab variables
Lecture two
Matlab final year project in jalandhar
Matlab final year project in ludhiana

What's hot (18)

PDF
Matlab HTI summer training course_Lecture2
PPTX
Matlab HTI summer training course Lecture3
PDF
Matlab tutorial 1
PPTX
Matrices in matlab
PPT
vlsi training in chandigarh
PPT
data mining training in Bangalore
DOC
Matlab tut2
PDF
Summary of MATLAB Functions-Part1
PDF
Matlab lecture 6 – newton raphson method@taj copy
PPTX
Matlab
DOC
Matlab summary
PPTX
NACA Regula Falsi Method
PPTX
Introduction to MATLAB
PDF
working with matrices in r
PPT
Merge sort
PPTX
Matlab matrices and arrays
PPTX
Matlab presentation
PPT
Introduction to matlab
Matlab HTI summer training course_Lecture2
Matlab HTI summer training course Lecture3
Matlab tutorial 1
Matrices in matlab
vlsi training in chandigarh
data mining training in Bangalore
Matlab tut2
Summary of MATLAB Functions-Part1
Matlab lecture 6 – newton raphson method@taj copy
Matlab
Matlab summary
NACA Regula Falsi Method
Introduction to MATLAB
working with matrices in r
Merge sort
Matlab matrices and arrays
Matlab presentation
Introduction to matlab
Ad

Viewers also liked (12)

PPTX
Presentation2
PDF
Tdc 2013 cum ne angajam
PPT
Meñoza(slide show) it1 hp2
PPTX
PPTX
Hallgrímur pétursson
PPT
IT1(HP2)_powerpoint presentation_Ocasiones
PDF
Matlab graphics
PPTX
Tdc 2013 career planning
PPTX
Presentation3
PPTX
Freys strategy in 5 years
PPTX
Katla 1
PPTX
Katla 1
Presentation2
Tdc 2013 cum ne angajam
Meñoza(slide show) it1 hp2
Hallgrímur pétursson
IT1(HP2)_powerpoint presentation_Ocasiones
Matlab graphics
Tdc 2013 career planning
Presentation3
Freys strategy in 5 years
Katla 1
Katla 1
Ad

Similar to Matlab matrics (20)

DOC
matlab Lesson 1
PPT
Matlab practical and lab session
PPT
Matlab introduction
PPT
Matlab Introduction Simulink and Basics ds
PPTX
Lecture 3.pptx
PDF
Matlab booklet
PDF
PPT
Matlab Overviiew 2
PPT
Matlab an Introduction_Lecture_for all.ppt
PPTX
Matlab Tutorial
PPTX
Importance of matlab
PPTX
MATLAB : Introduction , Features , Display Windows, Syntax, Operators, Graph...
PDF
Matlab ch1 intro
PDF
Matlab guide
PDF
Advanced MATLAB Tutorial for Engineers & Scientists
PDF
DOCX
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
PDF
Basic concepts in_matlab
PPTX
presentation.pptx
matlab Lesson 1
Matlab practical and lab session
Matlab introduction
Matlab Introduction Simulink and Basics ds
Lecture 3.pptx
Matlab booklet
Matlab Overviiew 2
Matlab an Introduction_Lecture_for all.ppt
Matlab Tutorial
Importance of matlab
MATLAB : Introduction , Features , Display Windows, Syntax, Operators, Graph...
Matlab ch1 intro
Matlab guide
Advanced MATLAB Tutorial for Engineers & Scientists
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
Basic concepts in_matlab
presentation.pptx

More from pramodkumar1804 (20)

PDF
Matlab syntax
PDF
Matlab strings
PDF
Matlab simulink
PDF
Matlab polynomials
PDF
Matlab plotting
PDF
Matlab overview 3
PDF
Matlab overview 2
PDF
Matlab overview
PDF
Matlab operators
PDF
Matlab numbers
PDF
Matlab m files
PDF
Matlab loops 2
PDF
Matlab loops
PDF
Matlab integration
PDF
Matlab gnu octave
PDF
Matlab operators
PDF
Matlab functions
PDF
Matlab differential
PDF
Matlab decisions
PDF
Matlab data import
Matlab syntax
Matlab strings
Matlab simulink
Matlab polynomials
Matlab plotting
Matlab overview 3
Matlab overview 2
Matlab overview
Matlab operators
Matlab numbers
Matlab m files
Matlab loops 2
Matlab loops
Matlab integration
Matlab gnu octave
Matlab operators
Matlab functions
Matlab differential
Matlab decisions
Matlab data import

Recently uploaded (20)

PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
RMMM.pdf make it easy to upload and study
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Module 4: Burden of Disease Tutorial Slides S2 2025
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
GDM (1) (1).pptx small presentation for students
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
Complications of Minimal Access Surgery at WLH
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Classroom Observation Tools for Teachers
PPTX
Final Presentation General Medicine 03-08-2024.pptx
Anesthesia in Laparoscopic Surgery in India
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
RMMM.pdf make it easy to upload and study
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Module 4: Burden of Disease Tutorial Slides S2 2025
102 student loan defaulters named and shamed – Is someone you know on the list?
GDM (1) (1).pptx small presentation for students
A systematic review of self-coping strategies used by university students to ...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Abdominal Access Techniques with Prof. Dr. R K Mishra
human mycosis Human fungal infections are called human mycosis..pptx
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Chinmaya Tiranga quiz Grand Finale.pdf
01-Introduction-to-Information-Management.pdf
Complications of Minimal Access Surgery at WLH
Microbial disease of the cardiovascular and lymphatic systems
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Classroom Observation Tools for Teachers
Final Presentation General Medicine 03-08-2024.pptx

Matlab matrics

  • 1. http://www.tutorialspoint.com/matlab/matlab_matrics.htm Copyright © tutorialspoint.com MATLAB - MATRIX A matrix is a two-dimensionalarray of numbers. InMATLAB, youcreate a matrix by entering elements ineachrow as comma or space delimited numbers and using semicolons to mark the end of eachrow. For example, let us create a 4-by-5 matrix a: a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8] MATLAB willexecute the above statement and returnthe following result: a = 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 4 5 6 7 8 Referencing the Elements of a Matrix To reference anelement inthe mth row and nth column, of a matrix mx, we write: mx(m, n); For example, to refer to the element inthe 2nd row and 5th column, of the matrix a, as created inthe last section, we type: a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8]; a(2,5) MATLAB willexecute the above statement and returnthe following result: ans = 6 To reference allthe elements inthe mth columnwe type A(:,m). Let us create a columnvector v, fromthe elements of the 4th row of the matrix a: a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8]; v = a(:,4) MATLAB willexecute the above statement and returnthe following result: v = 4 5 6 7 Youcanalso select the elements inthe mth throughnth columns, for this we write: a(:,m:n) Let us create a smaller matrix taking the elements fromthe second and third columns: a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8];
  • 2. a(:, 2:3) MATLAB willexecute the above statement and returnthe following result: ans = 2 3 3 4 4 5 5 6 Inthe same way, youcancreate a sub-matrix taking a sub-part of a matrix. a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8]; a(:, 2:3) MATLAB willexecute the above statement and returnthe following result: ans = 2 3 3 4 4 5 5 6 Inthe same way, youcancreate a sub-matrix taking a sub-part of a matrix. For example, let us create a sub-matrix sa taking the inner subpart of a: 3 4 5 4 5 6 To do this, write: a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8]; sa = a(2:3,2:4) MATLAB willexecute the above statement and returnthe following result: sa = 3 4 5 4 5 6 Deleting a Row or a Column in a Matrix Youcandelete anentire row or columnof a matrix by assigning anempty set of square braces [] to that row or column. Basically, [] denotes anempty array. For example, let us delete the fourthrow of a: a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8]; a( 4 , : ) = [] MATLAB willexecute the above statement and returnthe following result: a = 1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 Next, let us delete the fifthcolumnof a: a = [ 1 2 3 4 5; 2 3 4 5 6; 3 4 5 6 7; 4 5 6 7 8]; a(: , 5)=[]
  • 3. MATLAB willexecute the above statement and returnthe following result: a = 1 2 3 4 2 3 4 5 3 4 5 6 4 5 6 7 Example Inthis example, let us create a 3-by-3 matrix m, thenwe willcopy the second and third rows of this matrix twice to create a 4-by-3 matrix. Create a script file withthe following code: a = [ 1 2 3 ; 4 5 6; 7 8 9]; new_mat = a([2,3,2,3],:) Whenyourunthe file, it displays the following result: new_mat = 4 5 6 7 8 9 4 5 6 7 8 9 Matrix Operations Inthis section, let us discuss the following basic and commonly used matrix operations: Additionand Subtractionof Matrices Divisionof Matrices Scalar Operations of Matrices Transpose of a Matrix Concatenating Matrices Matrix Multiplication Determinant of a Matrix Inverse of a Matrix