SlideShare a Scribd company logo
1 of 2
Download to read offline
http://www.tutorialspoint.com/matlab/matlab_colon_notation.htm Copyright © tutorialspoint.com
MATLAB - COLON NOTATION
The colon(:) is one of the most usefuloperator inMATLAB. It is used to create vectors, subscript arrays, and
specify for iterations.
If youwant to create a row vector, containing integers from1 to 10, youwrite:
1:10
MATLAB executes the statement and returns a row vector containing the integers from1 to 10:
ans =
1 2 3 4 5 6 7 8 9 10
If youwant to specify anincrement value other thanone, for example:
100: -5: 50
MATLAB executes the statement and returns the following result:
ans =
100 95 90 85 80 75 70 65 60 55 50
Let us take another example:
0:pi/8:pi
MATLAB executes the statement and returns the following result:
ans =
Columns 1 through 7
0 0.3927 0.7854 1.1781 1.5708 1.9635 2.3562
Columns 8 through 9
2.7489 3.1416
Youcanuse the colonoperator to create a vector of indices to select rows, columns or elements of arrays.
The following table describes its use for this purpose (let us have a matrix A):
Format Purpose
A(:,j) is the jthcolumnof A.
A(i,:) is the ithrow of A.
A(:,:) is the equivalent two-dimensionalarray. For matrices this is the same as A.
A(j:k) is A(j), A(j+1),...,A(k).
A(:,j:k) is A(:,j), A(:,j+1),...,A(:,k).
A(:,:,k) is the kth page of three-dimensionalarray A.
A(i,j,k,:) is a vector infour-dimensionalarray A. The vector includes A(i,j,k,1), A(i,j,k,2), A(i,j,k,3),
and so on.
A(:) is allthe elements of A, regarded as a single column. Onthe left side of anassignment
statement, A(:) fills A, preserving its shape frombefore. Inthis case, the right side must
containthe same number of elements as A.
Example
Create a script file and type the following code init:
A = [1 2 3 4; 4 5 6 7; 7 8 9 10]
A(:,2) % second column of A
A(:,2:3) % second and third column of A
A(2:3,2:3) % second and third rows and second and third columns
Whenyourunthe file, it displays the following result:
A =
1 2 3 4
4 5 6 7
7 8 9 10
ans =
2
5
8
ans =
2 3
5 6
8 9
ans =
5 6
8 9

More Related Content

What's hot

A2 1 linear fxns
A2 1 linear fxns A2 1 linear fxns
A2 1 linear fxns vhiggins1
 
How to combine interpolation and regression graphs in R
How to combine interpolation and regression graphs in RHow to combine interpolation and regression graphs in R
How to combine interpolation and regression graphs in RDougLoqa
 
Pre-Cal 30S January 19, 2009
Pre-Cal 30S January 19, 2009Pre-Cal 30S January 19, 2009
Pre-Cal 30S January 19, 2009Darren Kuropatwa
 
Examplelf flowchart
Examplelf flowchartExamplelf flowchart
Examplelf flowchartAnkit Dubey
 
(724429257) cylindrical coordinate system (1)
(724429257) cylindrical coordinate system (1)(724429257) cylindrical coordinate system (1)
(724429257) cylindrical coordinate system (1)LingalaSowjanya
 
MATLAB review questions 2014 15
MATLAB review questions 2014 15MATLAB review questions 2014 15
MATLAB review questions 2014 15chingtony mbuma
 
Properties of a Triangular Matrix
Properties of a Triangular MatrixProperties of a Triangular Matrix
Properties of a Triangular MatrixChristopher Gratton
 
Graphing Power Pt
Graphing Power PtGraphing Power Pt
Graphing Power Ptmcmullan
 
Sequential multiplication
Sequential multiplicationSequential multiplication
Sequential multiplicationTaqwa It Center
 
GUASS’S ELIMINATION METHOD AND EXAMPLE
GUASS’S ELIMINATION METHOD AND EXAMPLEGUASS’S ELIMINATION METHOD AND EXAMPLE
GUASS’S ELIMINATION METHOD AND EXAMPLEBangulkhanbaloch
 
Trigonometric, hyperbolic functions with invers and sum function
Trigonometric, hyperbolic functions with invers and sum functionTrigonometric, hyperbolic functions with invers and sum function
Trigonometric, hyperbolic functions with invers and sum functionDlearAhmad
 
Algebra 2 project
Algebra 2 projectAlgebra 2 project
Algebra 2 projectjanlee97
 
Sequential circuit multiplier
Sequential circuit multiplierSequential circuit multiplier
Sequential circuit multiplierSubhram
 

What's hot (20)

A2 1 linear fxns
A2 1 linear fxns A2 1 linear fxns
A2 1 linear fxns
 
How to combine interpolation and regression graphs in R
How to combine interpolation and regression graphs in RHow to combine interpolation and regression graphs in R
How to combine interpolation and regression graphs in R
 
Pre-Cal 30S January 19, 2009
Pre-Cal 30S January 19, 2009Pre-Cal 30S January 19, 2009
Pre-Cal 30S January 19, 2009
 
Automata
AutomataAutomata
Automata
 
Matlab tutorial 1
Matlab tutorial 1Matlab tutorial 1
Matlab tutorial 1
 
Examplelf flowchart
Examplelf flowchartExamplelf flowchart
Examplelf flowchart
 
(724429257) cylindrical coordinate system (1)
(724429257) cylindrical coordinate system (1)(724429257) cylindrical coordinate system (1)
(724429257) cylindrical coordinate system (1)
 
MATLAB review questions 2014 15
MATLAB review questions 2014 15MATLAB review questions 2014 15
MATLAB review questions 2014 15
 
Properties of a Triangular Matrix
Properties of a Triangular MatrixProperties of a Triangular Matrix
Properties of a Triangular Matrix
 
Graphing Power Pt
Graphing Power PtGraphing Power Pt
Graphing Power Pt
 
Functions
FunctionsFunctions
Functions
 
Sequential multiplication
Sequential multiplicationSequential multiplication
Sequential multiplication
 
GUASS’S ELIMINATION METHOD AND EXAMPLE
GUASS’S ELIMINATION METHOD AND EXAMPLEGUASS’S ELIMINATION METHOD AND EXAMPLE
GUASS’S ELIMINATION METHOD AND EXAMPLE
 
Trigonometric, hyperbolic functions with invers and sum function
Trigonometric, hyperbolic functions with invers and sum functionTrigonometric, hyperbolic functions with invers and sum function
Trigonometric, hyperbolic functions with invers and sum function
 
Algorithms
AlgorithmsAlgorithms
Algorithms
 
Difcalc10week3
Difcalc10week3Difcalc10week3
Difcalc10week3
 
Algebra 2 project
Algebra 2 projectAlgebra 2 project
Algebra 2 project
 
Sequential circuit multiplier
Sequential circuit multiplierSequential circuit multiplier
Sequential circuit multiplier
 
Difcalc10week2
Difcalc10week2Difcalc10week2
Difcalc10week2
 
DiffCalcFirstParti
DiffCalcFirstPartiDiffCalcFirstParti
DiffCalcFirstParti
 

Similar to Matlab colon notation

1. Introduction.pptx
1. Introduction.pptx1. Introduction.pptx
1. Introduction.pptxSungaleliYuen
 
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docxMATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docxandreecapon
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlabkrajeshk1980
 
Digital communication lab lectures
Digital communication lab  lecturesDigital communication lab  lectures
Digital communication lab lecturesmarwaeng
 
Introduction to matlab lecture 2 of 4
Introduction to matlab lecture 2 of 4Introduction to matlab lecture 2 of 4
Introduction to matlab lecture 2 of 4Randa Elanwar
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxagnesdcarey33086
 
Matlab practice
Matlab practiceMatlab practice
Matlab practiceZunAib Ali
 
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 projectsMukesh Kumar
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsRai University
 

Similar to Matlab colon notation (20)

1. Introduction.pptx
1. Introduction.pptx1. Introduction.pptx
1. Introduction.pptx
 
1
11
1
 
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docxMATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
MATLAB sessions Laboratory 2MAT 275 Laboratory 2Matrix .docx
 
Importance of matlab
Importance of matlabImportance of matlab
Importance of matlab
 
Digital communication lab lectures
Digital communication lab  lecturesDigital communication lab  lectures
Digital communication lab lectures
 
Introduction to matlab lecture 2 of 4
Introduction to matlab lecture 2 of 4Introduction to matlab lecture 2 of 4
Introduction to matlab lecture 2 of 4
 
Basic concepts in_matlab
Basic concepts in_matlabBasic concepts in_matlab
Basic concepts in_matlab
 
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docxSAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
SAMPLE QUESTIONExercise 1 Consider the functionf (x,C).docx
 
Matlab booklet
Matlab bookletMatlab booklet
Matlab booklet
 
Matlab practice
Matlab practiceMatlab practice
Matlab practice
 
Introduction to MATLAB
Introduction to MATLABIntroduction to MATLAB
Introduction to MATLAB
 
MATLAB
MATLABMATLAB
MATLAB
 
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
 
Matlabtut1
Matlabtut1Matlabtut1
Matlabtut1
 
Environmental Engineering Assignment Help
Environmental Engineering Assignment HelpEnvironmental Engineering Assignment Help
Environmental Engineering Assignment Help
 
Mcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and stringsMcai pic u 4 function, storage class and array and strings
Mcai pic u 4 function, storage class and array and strings
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
MatlabIntro.ppt
MatlabIntro.pptMatlabIntro.ppt
MatlabIntro.ppt
 
Matlab intro
Matlab introMatlab intro
Matlab intro
 

More from pramodkumar1804 (20)

Matlab syntax
Matlab syntaxMatlab syntax
Matlab syntax
 
Matlab strings
Matlab stringsMatlab strings
Matlab strings
 
Matlab simulink
Matlab simulinkMatlab simulink
Matlab simulink
 
Matlab polynomials
Matlab polynomialsMatlab polynomials
Matlab polynomials
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
Matlab overview 3
Matlab overview 3Matlab overview 3
Matlab overview 3
 
Matlab overview 2
Matlab overview 2Matlab overview 2
Matlab overview 2
 
Matlab overview
Matlab overviewMatlab overview
Matlab overview
 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
 
Matlab variables
Matlab variablesMatlab variables
Matlab variables
 
Matlab numbers
Matlab numbersMatlab numbers
Matlab numbers
 
Matlab matrics
Matlab matricsMatlab matrics
Matlab matrics
 
Matlab m files
Matlab m filesMatlab m files
Matlab m files
 
Matlab loops 2
Matlab loops 2Matlab loops 2
Matlab loops 2
 
Matlab loops
Matlab loopsMatlab loops
Matlab loops
 
Matlab integration
Matlab integrationMatlab integration
Matlab integration
 
Matlab graphics
Matlab graphicsMatlab graphics
Matlab graphics
 
Matlab gnu octave
Matlab gnu octaveMatlab gnu octave
Matlab gnu octave
 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
 
Matlab functions
Matlab functionsMatlab functions
Matlab functions
 

Recently uploaded

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeThiyagu K
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Krashi Coaching
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxRoyAbrique
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdfQucHHunhnh
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104misteraugie
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Sapana Sha
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionSafetyChain Software
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...Marc Dusseiller Dusjagr
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityGeoBlogs
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxheathfieldcps1
 

Recently uploaded (20)

Measures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and ModeMeasures of Central Tendency: Mean, Median and Mode
Measures of Central Tendency: Mean, Median and Mode
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
Kisan Call Centre - To harness potential of ICT in Agriculture by answer farm...
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptxContemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
Contemporary philippine arts from the regions_PPT_Module_12 [Autosaved] (1).pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptxINDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
INDIA QUIZ 2024 RLAC DELHI UNIVERSITY.pptx
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1Código Creativo y Arte de Software | Unidad 1
Código Creativo y Arte de Software | Unidad 1
 
Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104Nutritional Needs Presentation - HLTH 104
Nutritional Needs Presentation - HLTH 104
 
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"Mattingly "AI & Prompt Design: The Basics of Prompt Design"
Mattingly "AI & Prompt Design: The Basics of Prompt Design"
 
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111Call Girls in Dwarka Mor Delhi Contact Us 9654467111
Call Girls in Dwarka Mor Delhi Contact Us 9654467111
 
Mastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory InspectionMastering the Unannounced Regulatory Inspection
Mastering the Unannounced Regulatory Inspection
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
“Oh GOSH! Reflecting on Hackteria's Collaborative Practices in a Global Do-It...
 
Paris 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activityParis 2024 Olympic Geographies - an activity
Paris 2024 Olympic Geographies - an activity
 
The basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptxThe basics of sentences session 2pptx copy.pptx
The basics of sentences session 2pptx copy.pptx
 

Matlab colon notation

  • 1. http://www.tutorialspoint.com/matlab/matlab_colon_notation.htm Copyright © tutorialspoint.com MATLAB - COLON NOTATION The colon(:) is one of the most usefuloperator inMATLAB. It is used to create vectors, subscript arrays, and specify for iterations. If youwant to create a row vector, containing integers from1 to 10, youwrite: 1:10 MATLAB executes the statement and returns a row vector containing the integers from1 to 10: ans = 1 2 3 4 5 6 7 8 9 10 If youwant to specify anincrement value other thanone, for example: 100: -5: 50 MATLAB executes the statement and returns the following result: ans = 100 95 90 85 80 75 70 65 60 55 50 Let us take another example: 0:pi/8:pi MATLAB executes the statement and returns the following result: ans = Columns 1 through 7 0 0.3927 0.7854 1.1781 1.5708 1.9635 2.3562 Columns 8 through 9 2.7489 3.1416 Youcanuse the colonoperator to create a vector of indices to select rows, columns or elements of arrays. The following table describes its use for this purpose (let us have a matrix A): Format Purpose A(:,j) is the jthcolumnof A. A(i,:) is the ithrow of A. A(:,:) is the equivalent two-dimensionalarray. For matrices this is the same as A. A(j:k) is A(j), A(j+1),...,A(k). A(:,j:k) is A(:,j), A(:,j+1),...,A(:,k). A(:,:,k) is the kth page of three-dimensionalarray A. A(i,j,k,:) is a vector infour-dimensionalarray A. The vector includes A(i,j,k,1), A(i,j,k,2), A(i,j,k,3), and so on. A(:) is allthe elements of A, regarded as a single column. Onthe left side of anassignment statement, A(:) fills A, preserving its shape frombefore. Inthis case, the right side must
  • 2. containthe same number of elements as A. Example Create a script file and type the following code init: A = [1 2 3 4; 4 5 6 7; 7 8 9 10] A(:,2) % second column of A A(:,2:3) % second and third column of A A(2:3,2:3) % second and third rows and second and third columns Whenyourunthe file, it displays the following result: A = 1 2 3 4 4 5 6 7 7 8 9 10 ans = 2 5 8 ans = 2 3 5 6 8 9 ans = 5 6 8 9