SlideShare a Scribd company logo
http://www.tutorialspoint.com/matlab/matlab_plotting .htm Copyright © tutorialspoint.com
MATLAB - PLOTTING
To plot the graphof a function, youneed to take the following steps:
1. Define x, by specifying the range of values for the variable x, for whichthe functionis to be plotted
2. Define the function, y = f(x)
3. Callthe plot command, as plot(x, y)
Following example would demonstrate the concept. Let us plot the simple functiony = x for the range of values
for x from0 to 100, withanincrement of 5.
Create a script file and type the following code:
x = [0:5:100];
y = x;
plot(x, y)
Whenyourunthe file, MATLAB displays the following plot:
Let us take one more example to plot the functiony = x2. Inthis example, we willdraw two graphs withthe same
function, but insecond time, we willreduce the value of increment. Please note that as we decrease the
increment, the graphbecomes smoother.
Create a script file and type the following code:
x = [1 2 3 4 5 6 7 8 9 10];
x = [-100:20:100];
y = x.^2;
plot(x, y)
Whenyourunthe file, MATLAB displays the following plot:
Change the code file a little, reduce the increment to 5:
x = [-100:5:100];
y = x.^2;
plot(x, y)
MATLAB draws a smoother graph:
Adding Title, Labels, Grid Lines and Scaling on the Graph
MATLAB allows youto add title, labels along the x-axis and y-axis, grid lines and also to adjust the axes to
spruce up the graph.
The xlabel and ylabel commands generate labels along x-axis and y-axis.
The title command allows youto put a title onthe graph.
The grid on command allows youto put the grid lines onthe graph.
The axis equal command allows generating the plot withthe same scale factors and the spaces onboth
axes.
The axis square command generates a square plot.
Example
Create a script file and type the following code:
x = [0:0.01:10];
y = sin(x);
plot(x, y), xlabel('x'), ylabel('Sin(x)'), title('Sin(x) Graph'),
grid on, axis equal
MATLAB generates the following graph:
Drawing Multiple Functions on the Same Graph
Youcandraw multiple graphs onthe same plot. The following example demonstrates the concept:
Example
Create a script file and type the following code:
x = [0 : 0.01: 10];
y = sin(x);
g = cos(x);
plot(x, y, x, g, '.-'), legend('Sin(x)', 'Cos(x)')
MATLAB generates the following graph:
Setting Colors on Graph
MATLAB provides eight basic color options for drawing graphs. The following table shows the colors and their
codes:
Color Code
White w
Black k
Blue b
Red r
Cyan c
Green g
Magenta m
Yellow y
Example
Let us draw the graphof two polynomials
1. f(x) = 3x4 + 2x3+ 7x2 + 2x + 9 and
2. g(x) = 5x3 + 9x + 2
Create a script file and type the following code:
x = [-10 : 0.01: 10];
y = 3*x.^4 + 2 * x.^3 + 7 * x.^2 + 2 * x + 9;
g = 5 * x.^3 + 9 * x + 2;
plot(x, y, 'r', x, g, 'g')
Whenyourunthe file, MATLAB generates the following graph:
Setting Axis Scales
The axis command allows youto set the axis scales. Youcanprovide minimumand maximumvalues for x and y
axes using the axis command inthe following way:
axis ( [xmin xmax ymin ymax] )
The following example shows this:
Example
Create a script file and type the following code:
x = [0 : 0.01: 10];
y = exp(-x).* sin(2*x + 3);
plot(x, y), axis([0 10 -1 1])
Whenyourunthe file, MATLAB generates the following graph:
Generating Sub-Plots
Whenyoucreate anarray of plots inthe same figure, eachof these plots is called a subplot. The subplot
command is for creating subplots.
Syntax for the command is:
subplot(m, n, p)
where, m and n are the number of rows and columns of the plot array and p specifies where to put a particular
plot.
Eachplot created withthe subplot command canhave its owncharacteristics. Following example demonstrates
the concept:
Example
Let us generate two plots:
y = e−1.5xsin(10x)
y = e−2xsin(10x)
Create a script file and type the following code:
x = [0:0.01:5];
y = exp(-1.5*x).*sin(10*x);
subplot(1,2,1)
plot(x,y), xlabel('x'),ylabel('exp(–1.5x)*sin(10x)'),axis([0 5 -1 1])
y = exp(-2*x).*sin(10*x);
subplot(1,2,2)
plot(x,y),xlabel('x'),ylabel('exp(–2x)*sin(10x)'),axis([0 5 -1 1])
Whenyourunthe file, MATLAB generates the following graph:

More Related Content

What's hot

Numerical solution of system of linear equations
Numerical solution of system of linear equationsNumerical solution of system of linear equations
Numerical solution of system of linear equations
reach2arkaELECTRICAL
 
Bootstrap 5 ppt
Bootstrap 5 pptBootstrap 5 ppt
Bootstrap 5 ppt
Mallikarjuna G D
 
Solution Manual : Chapter - 02 Limits and Continuity
Solution Manual : Chapter - 02 Limits and ContinuitySolution Manual : Chapter - 02 Limits and Continuity
Solution Manual : Chapter - 02 Limits and Continuity
Hareem Aslam
 
Partial differentiation B tech
Partial differentiation B techPartial differentiation B tech
Partial differentiation B tech
Raj verma
 
Unit ii java script and xhtml documents and dynamic documents with javascript
Unit ii java script and xhtml documents and dynamic documents with javascriptUnit ii java script and xhtml documents and dynamic documents with javascript
Unit ii java script and xhtml documents and dynamic documents with javascript
zahid7578
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
Md. Mahedee Hasan
 
Web Development syllabus
Web Development syllabusWeb Development syllabus
Web Development syllabus
Pramuka Amarakeerthi
 
Introduction to latex by Rouhollah Nabati
Introduction to latex by Rouhollah NabatiIntroduction to latex by Rouhollah Nabati
Introduction to latex by Rouhollah Nabati
nabati
 
JavaScript Functions
JavaScript Functions JavaScript Functions
JavaScript Functions
Reem Alattas
 
Box Model
Box ModelBox Model
Box Model
Amit Kumar Singh
 
Complex numbers 2
Complex numbers 2Complex numbers 2
Complex numbers 2
Dr. Nirav Vyas
 
Solution of matlab chapter 1
Solution of matlab chapter 1Solution of matlab chapter 1
Solution of matlab chapter 1
AhsanIrshad8
 
Double Integral Powerpoint
Double Integral PowerpointDouble Integral Powerpoint
Double Integral Powerpoint
oaishnosaj
 
MATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesMATLAB - Arrays and Matrices
MATLAB - Arrays and Matrices
Shameer Ahmed Koya
 
Loops in matlab
Loops in matlabLoops in matlab
Loops in matlabTUOS-Sam
 
JavaScript - Part-1
JavaScript - Part-1JavaScript - Part-1
JavaScript - Part-1
Jainul Musani
 
Numerical Methods - Oridnary Differential Equations - 1
Numerical Methods - Oridnary Differential Equations - 1Numerical Methods - Oridnary Differential Equations - 1
Numerical Methods - Oridnary Differential Equations - 1
Dr. Nirav Vyas
 
JavaScript and jQuery - Web Technologies (1019888BNR)
JavaScript and jQuery - Web Technologies (1019888BNR)JavaScript and jQuery - Web Technologies (1019888BNR)
JavaScript and jQuery - Web Technologies (1019888BNR)
Beat Signer
 
NUMERICAL METHODS
NUMERICAL METHODSNUMERICAL METHODS
NUMERICAL METHODS
PRABHAHARAN429
 
11 graphs of first degree functions x
11 graphs of first degree functions x11 graphs of first degree functions x
11 graphs of first degree functions x
math260
 

What's hot (20)

Numerical solution of system of linear equations
Numerical solution of system of linear equationsNumerical solution of system of linear equations
Numerical solution of system of linear equations
 
Bootstrap 5 ppt
Bootstrap 5 pptBootstrap 5 ppt
Bootstrap 5 ppt
 
Solution Manual : Chapter - 02 Limits and Continuity
Solution Manual : Chapter - 02 Limits and ContinuitySolution Manual : Chapter - 02 Limits and Continuity
Solution Manual : Chapter - 02 Limits and Continuity
 
Partial differentiation B tech
Partial differentiation B techPartial differentiation B tech
Partial differentiation B tech
 
Unit ii java script and xhtml documents and dynamic documents with javascript
Unit ii java script and xhtml documents and dynamic documents with javascriptUnit ii java script and xhtml documents and dynamic documents with javascript
Unit ii java script and xhtml documents and dynamic documents with javascript
 
Object Oriented Programming
Object Oriented ProgrammingObject Oriented Programming
Object Oriented Programming
 
Web Development syllabus
Web Development syllabusWeb Development syllabus
Web Development syllabus
 
Introduction to latex by Rouhollah Nabati
Introduction to latex by Rouhollah NabatiIntroduction to latex by Rouhollah Nabati
Introduction to latex by Rouhollah Nabati
 
JavaScript Functions
JavaScript Functions JavaScript Functions
JavaScript Functions
 
Box Model
Box ModelBox Model
Box Model
 
Complex numbers 2
Complex numbers 2Complex numbers 2
Complex numbers 2
 
Solution of matlab chapter 1
Solution of matlab chapter 1Solution of matlab chapter 1
Solution of matlab chapter 1
 
Double Integral Powerpoint
Double Integral PowerpointDouble Integral Powerpoint
Double Integral Powerpoint
 
MATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesMATLAB - Arrays and Matrices
MATLAB - Arrays and Matrices
 
Loops in matlab
Loops in matlabLoops in matlab
Loops in matlab
 
JavaScript - Part-1
JavaScript - Part-1JavaScript - Part-1
JavaScript - Part-1
 
Numerical Methods - Oridnary Differential Equations - 1
Numerical Methods - Oridnary Differential Equations - 1Numerical Methods - Oridnary Differential Equations - 1
Numerical Methods - Oridnary Differential Equations - 1
 
JavaScript and jQuery - Web Technologies (1019888BNR)
JavaScript and jQuery - Web Technologies (1019888BNR)JavaScript and jQuery - Web Technologies (1019888BNR)
JavaScript and jQuery - Web Technologies (1019888BNR)
 
NUMERICAL METHODS
NUMERICAL METHODSNUMERICAL METHODS
NUMERICAL METHODS
 
11 graphs of first degree functions x
11 graphs of first degree functions x11 graphs of first degree functions x
11 graphs of first degree functions x
 

Viewers also liked

matlab functions
 matlab functions  matlab functions
matlab functions
DINESH DEVIREDDY
 
Matlab tutorial
Matlab tutorialMatlab tutorial
Matlab tutorial
Grace_Indah
 
graphs plotting in MATLAB
graphs plotting in MATLABgraphs plotting in MATLAB
graphs plotting in MATLAB
Apurva Patil
 
Matlab
MatlabMatlab
Matlab
sandhya jois
 
Mit6 094 iap10_lec01
Mit6 094 iap10_lec01Mit6 094 iap10_lec01
Mit6 094 iap10_lec01
Tribhuwan Pant
 
2D Plot Matlab
2D Plot Matlab2D Plot Matlab
2D Plot Matlab
Jorge Jasso
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
Murshida ck
 

Viewers also liked (7)

matlab functions
 matlab functions  matlab functions
matlab functions
 
Matlab tutorial
Matlab tutorialMatlab tutorial
Matlab tutorial
 
graphs plotting in MATLAB
graphs plotting in MATLABgraphs plotting in MATLAB
graphs plotting in MATLAB
 
Matlab
MatlabMatlab
Matlab
 
Mit6 094 iap10_lec01
Mit6 094 iap10_lec01Mit6 094 iap10_lec01
Mit6 094 iap10_lec01
 
2D Plot Matlab
2D Plot Matlab2D Plot Matlab
2D Plot Matlab
 
An Introduction to MATLAB for beginners
An Introduction to MATLAB for beginnersAn Introduction to MATLAB for beginners
An Introduction to MATLAB for beginners
 

Similar to Matlab plotting

Matlab graphics
Matlab graphicsMatlab graphics
Matlab graphics
pramodkumar1804
 
Programming with matlab session 6
Programming with matlab session 6Programming with matlab session 6
Programming with matlab session 6
Infinity Tech Solutions
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxMore instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docx
gilpinleeanna
 
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
agnesdcarey33086
 
Matlab integration
Matlab integrationMatlab integration
Matlab integration
pramodkumar1804
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
Mohd Esa
 
Tutorial 2
Tutorial     2Tutorial     2
Tutorial 2
Mohamed Yaser
 
COMPANION TO MATRICES SESSION III.pptx
COMPANION TO MATRICES SESSION III.pptxCOMPANION TO MATRICES SESSION III.pptx
COMPANION TO MATRICES SESSION III.pptx
imman gwu
 
Matlab algebra
Matlab algebraMatlab algebra
Matlab algebra
pramodkumar1804
 
Matlab 1
Matlab 1Matlab 1
Matlab 1asguna
 
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
anhlodge
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
Golden Julie Jesus
 
Lecture 2 f17
Lecture 2 f17Lecture 2 f17
Lecture 2 f17
Eric Cochran
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkTUOS-Sam
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
raghav415187
 
Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1
Philip Schwarz
 

Similar to Matlab plotting (20)

Lesson 3
Lesson 3Lesson 3
Lesson 3
 
Matlab graphics
Matlab graphicsMatlab graphics
Matlab graphics
 
Programming with matlab session 6
Programming with matlab session 6Programming with matlab session 6
Programming with matlab session 6
 
More instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docxMore instructions for the lab write-up1) You are not obli.docx
More instructions for the lab write-up1) You are not obli.docx
 
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 integration
Matlab integrationMatlab integration
Matlab integration
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 
Mat lab
Mat labMat lab
Mat lab
 
Tutorial 2
Tutorial     2Tutorial     2
Tutorial 2
 
COMPANION TO MATRICES SESSION III.pptx
COMPANION TO MATRICES SESSION III.pptxCOMPANION TO MATRICES SESSION III.pptx
COMPANION TO MATRICES SESSION III.pptx
 
Matlab algebra
Matlab algebraMatlab algebra
Matlab algebra
 
Matlab 1
Matlab 1Matlab 1
Matlab 1
 
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
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
Lecture 2 f17
Lecture 2 f17Lecture 2 f17
Lecture 2 f17
 
Lec2
Lec2Lec2
Lec2
 
CIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & CourseworkCIV1900 Matlab - Plotting & Coursework
CIV1900 Matlab - Plotting & Coursework
 
presentation.pptx
presentation.pptxpresentation.pptx
presentation.pptx
 
Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1Computer Graphics in Java and Scala - Part 1
Computer Graphics in Java and Scala - Part 1
 
Matlab graphics
Matlab graphicsMatlab graphics
Matlab graphics
 

More from pramodkumar1804

Matlab syntax
Matlab syntaxMatlab syntax
Matlab syntax
pramodkumar1804
 
Matlab strings
Matlab stringsMatlab strings
Matlab strings
pramodkumar1804
 
Matlab simulink
Matlab simulinkMatlab simulink
Matlab simulink
pramodkumar1804
 
Matlab polynomials
Matlab polynomialsMatlab polynomials
Matlab polynomials
pramodkumar1804
 
Matlab overview 3
Matlab overview 3Matlab overview 3
Matlab overview 3
pramodkumar1804
 
Matlab overview 2
Matlab overview 2Matlab overview 2
Matlab overview 2
pramodkumar1804
 
Matlab overview
Matlab overviewMatlab overview
Matlab overview
pramodkumar1804
 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
pramodkumar1804
 
Matlab variables
Matlab variablesMatlab variables
Matlab variables
pramodkumar1804
 
Matlab numbers
Matlab numbersMatlab numbers
Matlab numbers
pramodkumar1804
 
Matlab matrics
Matlab matricsMatlab matrics
Matlab matrics
pramodkumar1804
 
Matlab m files
Matlab m filesMatlab m files
Matlab m files
pramodkumar1804
 
Matlab loops 2
Matlab loops 2Matlab loops 2
Matlab loops 2
pramodkumar1804
 
Matlab loops
Matlab loopsMatlab loops
Matlab loops
pramodkumar1804
 
Matlab gnu octave
Matlab gnu octaveMatlab gnu octave
Matlab gnu octave
pramodkumar1804
 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
pramodkumar1804
 
Matlab functions
Matlab functionsMatlab functions
Matlab functions
pramodkumar1804
 
Matlab differential
Matlab differentialMatlab differential
Matlab differential
pramodkumar1804
 
Matlab decisions
Matlab decisionsMatlab decisions
Matlab decisions
pramodkumar1804
 
Matlab data import
Matlab data importMatlab data import
Matlab data import
pramodkumar1804
 

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 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 gnu octave
Matlab gnu octaveMatlab gnu octave
Matlab gnu octave
 
Matlab operators
Matlab operatorsMatlab operators
Matlab operators
 
Matlab functions
Matlab functionsMatlab functions
Matlab functions
 
Matlab differential
Matlab differentialMatlab differential
Matlab differential
 
Matlab decisions
Matlab decisionsMatlab decisions
Matlab decisions
 
Matlab data import
Matlab data importMatlab data import
Matlab data import
 

Recently uploaded

Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
Wasim Ak
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
vaibhavrinwa19
 
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
 
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
 
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
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
Celine George
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
EugeneSaldivar
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
Peter Windle
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
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
 
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
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
JosvitaDsouza2
 
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
 
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
 
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
 
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
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
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 approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
Jisc
 

Recently uploaded (20)

Normal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of LabourNormal Labour/ Stages of Labour/ Mechanism of Labour
Normal Labour/ Stages of Labour/ Mechanism of Labour
 
Acetabularia Information For Class 9 .docx
Acetabularia Information For Class 9  .docxAcetabularia Information For Class 9  .docx
Acetabularia Information For Class 9 .docx
 
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
 
Operation Blue Star - Saka Neela Tara
Operation Blue Star   -  Saka Neela TaraOperation Blue Star   -  Saka Neela Tara
Operation Blue Star - Saka Neela Tara
 
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...
 
Model Attribute Check Company Auto Property
Model Attribute  Check Company Auto PropertyModel Attribute  Check Company Auto Property
Model Attribute Check Company Auto Property
 
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...TESDA TM1 REVIEWER  FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
TESDA TM1 REVIEWER FOR NATIONAL ASSESSMENT WRITTEN AND ORAL QUESTIONS WITH A...
 
Embracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic ImperativeEmbracing GenAI - A Strategic Imperative
Embracing GenAI - A Strategic Imperative
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
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
 
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
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx1.4 modern child centered education - mahatma gandhi-2.pptx
1.4 modern child centered education - mahatma gandhi-2.pptx
 
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
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
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
 
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...
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.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 approach at University of Liverpool.pptx
The approach at University of Liverpool.pptxThe approach at University of Liverpool.pptx
The approach at University of Liverpool.pptx
 

Matlab plotting

  • 1. http://www.tutorialspoint.com/matlab/matlab_plotting .htm Copyright © tutorialspoint.com MATLAB - PLOTTING To plot the graphof a function, youneed to take the following steps: 1. Define x, by specifying the range of values for the variable x, for whichthe functionis to be plotted 2. Define the function, y = f(x) 3. Callthe plot command, as plot(x, y) Following example would demonstrate the concept. Let us plot the simple functiony = x for the range of values for x from0 to 100, withanincrement of 5. Create a script file and type the following code: x = [0:5:100]; y = x; plot(x, y) Whenyourunthe file, MATLAB displays the following plot: Let us take one more example to plot the functiony = x2. Inthis example, we willdraw two graphs withthe same function, but insecond time, we willreduce the value of increment. Please note that as we decrease the increment, the graphbecomes smoother. Create a script file and type the following code: x = [1 2 3 4 5 6 7 8 9 10]; x = [-100:20:100]; y = x.^2; plot(x, y) Whenyourunthe file, MATLAB displays the following plot:
  • 2. Change the code file a little, reduce the increment to 5: x = [-100:5:100]; y = x.^2; plot(x, y) MATLAB draws a smoother graph: Adding Title, Labels, Grid Lines and Scaling on the Graph MATLAB allows youto add title, labels along the x-axis and y-axis, grid lines and also to adjust the axes to spruce up the graph. The xlabel and ylabel commands generate labels along x-axis and y-axis. The title command allows youto put a title onthe graph. The grid on command allows youto put the grid lines onthe graph. The axis equal command allows generating the plot withthe same scale factors and the spaces onboth axes.
  • 3. The axis square command generates a square plot. Example Create a script file and type the following code: x = [0:0.01:10]; y = sin(x); plot(x, y), xlabel('x'), ylabel('Sin(x)'), title('Sin(x) Graph'), grid on, axis equal MATLAB generates the following graph: Drawing Multiple Functions on the Same Graph Youcandraw multiple graphs onthe same plot. The following example demonstrates the concept: Example Create a script file and type the following code: x = [0 : 0.01: 10]; y = sin(x); g = cos(x); plot(x, y, x, g, '.-'), legend('Sin(x)', 'Cos(x)') MATLAB generates the following graph:
  • 4. Setting Colors on Graph MATLAB provides eight basic color options for drawing graphs. The following table shows the colors and their codes: Color Code White w Black k Blue b Red r Cyan c Green g Magenta m Yellow y Example Let us draw the graphof two polynomials 1. f(x) = 3x4 + 2x3+ 7x2 + 2x + 9 and 2. g(x) = 5x3 + 9x + 2 Create a script file and type the following code: x = [-10 : 0.01: 10]; y = 3*x.^4 + 2 * x.^3 + 7 * x.^2 + 2 * x + 9; g = 5 * x.^3 + 9 * x + 2; plot(x, y, 'r', x, g, 'g') Whenyourunthe file, MATLAB generates the following graph:
  • 5. Setting Axis Scales The axis command allows youto set the axis scales. Youcanprovide minimumand maximumvalues for x and y axes using the axis command inthe following way: axis ( [xmin xmax ymin ymax] ) The following example shows this: Example Create a script file and type the following code: x = [0 : 0.01: 10]; y = exp(-x).* sin(2*x + 3); plot(x, y), axis([0 10 -1 1]) Whenyourunthe file, MATLAB generates the following graph:
  • 6. Generating Sub-Plots Whenyoucreate anarray of plots inthe same figure, eachof these plots is called a subplot. The subplot command is for creating subplots. Syntax for the command is: subplot(m, n, p) where, m and n are the number of rows and columns of the plot array and p specifies where to put a particular plot. Eachplot created withthe subplot command canhave its owncharacteristics. Following example demonstrates the concept: Example Let us generate two plots: y = e−1.5xsin(10x) y = e−2xsin(10x) Create a script file and type the following code: x = [0:0.01:5]; y = exp(-1.5*x).*sin(10*x); subplot(1,2,1) plot(x,y), xlabel('x'),ylabel('exp(–1.5x)*sin(10x)'),axis([0 5 -1 1]) y = exp(-2*x).*sin(10*x); subplot(1,2,2) plot(x,y),xlabel('x'),ylabel('exp(–2x)*sin(10x)'),axis([0 5 -1 1]) Whenyourunthe file, MATLAB generates the following graph: