SlideShare a Scribd company logo
1 of 38
SESSION-6 :MATLAB
PLOTTING-2D, 3D
By: Prof. Ganesh Ingle
Session objective
Introdcution
Plotting basic 2-D plots.
The plot command
The fplot command
Plotting multiple graphs in the same plot
Formatting plots
SUMMARY
MAKING X-Y PLOTS
MATLAB has many functions and commands that can be used to create
various types of plots.
In our class we will only create two dimensional x – y plots.
8 10 12 14 16 18 20 22 24
0
200
400
600
800
1000
1200
DISTANCE (cm)
INTENSITY(lux)
Light Intensity as a Function of Distance
Comparison between theory and experiment.
Theory
Experiment
Plot title
y axis
label
x axis
label
Text
Tick-mark label
EXAMPLE OF A 2-D PLOT
Data symbol
Legend
Tick-mark
Plotting
TWO-DIMENSIONAL plot() COMMAND
where x is a vector (one dimensional array), and y is a vector.
Both vectors must have the same number of elements.
 The plot command creates a single curve with the x values on
the abscissa (horizontal axis) and the y values on the ordinate
(vertical axis).
 The curve is made from segments of lines that connect the
points that are defined by the x and y coordinates of the
elements in the two vectors.
The basic 2-D plot command is:
plot(x,y)
Plotting
 If data is given, the information is entered as the elements of the
vectors x and y.
 If the values of y are determined by a function from the values
of x, than a vector x is created first, and then the values of y
are calculated for each value of x. The spacing (difference)
between the elements of x must be such that the plotted curve
will show the details of the function.
CREATING THE X AND Y VECTORS
Plotting
PLOT OF GIVEN DATA
Given data:
>> x=[1 2 3 5 7 7.5 8 10];
>> y=[2 6.5 7 7 5.5 4 6 8];
>> plot(x,y)
A plot can be created by the commands shown below. This can be done
in the Command Window, or by writing and then running a script file.
Once the plot command is executed, the Figure Window opens with the
following plot.
x
y
1 2 3 5 7 7.5 8
6.5 7 7 5.5 4 6 8
10
2
Plotting
PLOT OF GIVEN DATA
Plotting
LINE SPECIFIERS IN THE plot() COMMAND
Line specifiers can be added in the plot command to:
 Specify the style of the line.
 Specify the color of the line.
 Specify the type of the markers (if markers are desired).
plot(x,y,’line specifiers’)
Plotting
LINE SPECIFIERS IN THE plot() COMMAND
Line Specifier Line Specifier Marker Specifier
Style Color Type
Solid - red r plus sign +
dotted : green g circle o
dashed -- blue b asterisk *
dash-dot -. Cyan c point .
magenta m square s
yellow y diamond d
black k
plot(x,y,‘line specifiers’)
Plotting
LINE SPECIFIERS IN THE plot() COMMAND
 The specifiers are typed inside the plot() command as strings.
 Within the string the specifiers can be typed in any order.
 The specifiers are optional. This means that none, one, two, or
all the three can be included in a command.
EXAMPLES:
plot(x,y) A solid blue line connects the points with no markers.
plot(x,y,’r’) A solid red line connects the points with no markers.
plot(x,y,’--y’) A yellow dashed line connects the points.
plot(x,y,’*’) The points are marked with * (no line between the
points.)
plot(x,y,’g:d’) A green dotted line connects the points which are
marked with diamond markers.
Plotting
Year
Sales (M)
1988 1989 1990 1991 1992 1993 1994
127 130 136 145 158 178 211
PLOT OF GIVEN DATA USING LINE
SPECIFIERS IN THE plot() COMMAND
>> year = [1988:1:1994];
>> sales = [127, 130, 136, 145, 158, 178, 211];
>> plot(year,sales,'--r*')
Line Specifiers:
dashed red line and
asterisk markers.
Plotting
PLOT OF GIVEN DATA USING LINE
SPECIFIERS IN THE plot() COMMAND
Dashed red line and
asterisk markers.
Plotting
PLOT OF GIVEN DATA USING LINE
SPECIFIERS IN THE plot() COMMAND
Dashed red line and
asterisk markers.
Plotting
% A script file that creates a plot of
% the function: 3.5^(-0.5x)*cos(6x)
x = [-2:0.01:4];
y = 3.5.^(-0.5*x).*cos(6*x);
plot(x,y)
CREATING A PLOT OF A FUNCTION
Consider: 42for)6cos(5.3 5.0
 
xxy x
A script file for plotting the function is:
Creating a vector with spacing of 0.01.
Calculating a value of y
for each x.
Once the plot command is executed, the Figure Window opens with the
following plot.
Plotting
A PLOT OF A FUNCTION
42for)6cos(5.3 5.0
 
xxy x
Plotting
CREATING A PLOT OF A FUNCTION
If the vector x is created with large spacing, the graph is not accurate.
Below is the previous plot with spacing of 0.3.
x = [-2:0.3:4];
y = 3.5.^(-0.5*x).*cos(6*x);
plot(x,y)
Plotting
THE fplot COMMAND
fplot(‘function’,limits)
The fplot command can be used to plot a function
with the form: y = f(x)
 The function is typed in as a string.
 The limits is a vector with the domain of x, and optionally with limits
of the y axis:
[xmin,xmax] or [xmin,xmax,ymin,ymax]
 Line specifiers can be added.
Plotting
PLOT OF A FUNCTION WITH THE fplot() COMMAND
>> fplot('x^2 + 4 * sin(2*x) - 1', [-3 3])
33for1)2sin(42
 xxxyA plot of:
Plotting
PLOTTING MULTIPLE GRAPHS IN THE SAME PLOT
Plotting two (or more) graphs in one plot:
1. Using the plot command.
2. Using the hold on, hold off commands.
Plotting
USING THE plot() COMMAND TO PLOT
MULTIPLE GRAPHS IN THE SAME PLOT
Plots three graphs in the same plot:
y versus x, v versus u, and h versus t.
 By default, MATLAB makes the curves in different colors.
 Additional curves can be added.
 The curves can have a specific style by adding specifiers after
each pair, for example:
plot(x,y,u,v,t,h)
plot(x,y,’-b’,u,v,’—r’,t,h,’g:’)
Plotting
USING THE plot() COMMAND TO PLOT
MULTIPLE GRAPHS IN THE SAME PLOT
42  x
Plot of the function, and its first and second
derivatives, for , all in the same plot.
10263 3
 xxy
42  x
x = [-2:0.01:4];
y = 3*x.^3-26*x+6;
yd = 9*x.^2-26;
ydd = 18*x;
plot(x,y,'-b',x,yd,'--r',x,ydd,':k')
vector x with the domain of the function.
Vector y with the function value at each x.
42  x
Vector yd with values of the first derivative.
Vector ydd with values of the second derivative.
Create three graphs, y vs. x (solid blue line),
yd vs. x (dashed red line), and ydd vs. x
(dotted black line) in the same figure.
Plotting
-2 -1 0 1 2 3 4
-40
-20
0
20
40
60
80
100
120
USING THE plot() COMMAND TO PLOT
MULTIPLE GRAPHS IN THE SAME PLOT
Plotting
hold on Holds the current plot and all axis properties so that
subsequent plot commands add to the existing plot.
hold off Returns to the default mode whereby plot commands
erase the previous plots and reset all axis properties
before drawing new plots.
USING THE hold on, hold off, COMMANDS
TO PLOT MULTIPLE GRAPHS IN THE SAME PLOT
This method is useful when all the information (vectors) used for the
plotting is not available a the same time.
Plotting
Plot of the function, and its first and second
derivatives, for all in the same plot.
10263 3
 xxy
42  x
x = [-2:0.01:4];
y = 3*x.^3-26*x+6;
yd = 9*x.^2-26;
ydd = 18*x;
plot(x,y,'-b')
hold on
plot(x,yd,'--r')
plot(x,ydd,':k')
hold off
Two more graphs are created.
First graph is created.
USING THE hold on, hold off, COMMANDS
TO PLOT MULTIPLE GRAPHS IN THE SAME PLOT
Plotting
8 10 12 14 16 18 20 22 24
0
200
400
600
800
1000
1200
DISTANCE (cm)
INTENSITY(lux)
Light Intensity as a Function of Distance
Comparison between theory and experiment.
Theory
Experiment
Plot title
y axis
label
x axis
label
Text
EXAMPLE OF A FORMATTED 2-D PLOT
Data symbol
Legend
Tick-mark
Tick-mark label
Plotting
FORMATTING PLOTS
A plot can be formatted to have a required appearance.
With formatting you can:
 Add title to the plot.
 Add labels to axes.
 Change range of the axes.
 Add legend.
 Add text blocks.
 Add grid.
Plotting
FORMATTING PLOTS
There are two methods to format a plot:
1. Formatting commands.
In this method commands, that make changes or additions to
the plot, are entered after the plot() command. This can be
done in the Command Window, or as part of a program in a
script file.
2. Formatting the plot interactively in the Figure Window.
In this method the plot is formatted by clicking on the plot and
using the menu to make changes or add details.
Plotting
FORMATTING COMMANDS
title(‘string’)
Adds the string as a title at the top of the plot.
xlabel(‘string’)
Adds the string as a label to the x-axis.
ylabel(‘string’)
Adds the string as a label to the y-axis.
axis([xmin xmax ymin ymax])
Sets the minimum and maximum limits of the x- and y-axes.
Plotting
FORMATTING COMMANDS
legend(‘string1’,’string2’,’string3’)
Creates a legend using the strings to label various curves (when
several curves are in one plot). The location of the legend is
specified by the mouse.
text(x,y,’string’)
Places the string (text) on the plot at coordinate x,y relative to
the plot axes.
gtext(‘string’)
Places the string (text) on the plot. When the command
executes the figure window pops and the text location is clicked
with the mouse.
Plotting
EXAMPLE OF A FORMATTED PLOT
Below is a script file of the formatted light intensity plot (2nd slide).
(Some of the formatting options were not covered in the lectures, but
are described in the book)
x=[10:0.1:22];
y=95000./x.^2;
xd=[10:2:22];
yd=[950 640 460 340 250 180 140];
plot(x,y,'-','LineWidth',1.0)
hold on
plot(xd,yd,'ro--','linewidth',1.0,'markersize',10)
hold off
Creating a vector with
light intensity from data.
Creating a vector with coordinates of data points.
Creating vector x for plotting the theoretical curve.
Creating vector y for plotting the theoretical curve.
Plotting
EXAMPLE OF A FORMATTED PLOT
Formatting of the light intensity plot (cont.)
xlabel('DISTANCE (cm)')
ylabel('INTENSITY (lux)')
title('fontname{Arial}Light Intensity as a Function of
Distance','FontSize',14)
axis([8 24 0 1200])
text(14,700,'Comparison between theory and
experiment.','EdgeColor','r','LineWidth',2)
legend('Theory','Experiment',0)
Creating text.
Creating a legend.
Title for the plot.
Setting limits of the axes.
Labels for the axes.
The plot that is obtained is shown again in the next slide.
Plotting
EXAMPLE OF A FORMATTED PLOT
Plotting
FORMATTING A PLOT IN THE FIGURE WINDOW
Once a figure window is open, the figure can be formatted interactively.
Use Figure, Axes,
and Current
Object-
Properties in the
Edit menu
Click here to start the
plot edit mode.
Use the insert menu to
Plotting
MATLAB PROGRAM TO PLOT VI CHARACTERISTICS OF A DIODE
%Matlab program to plot VI characteristics of a diode
clc;
close all;
clear all;
a=input('Enter the temperatre in degree centigrade '); %40
b=input('Enter the reverse saturation current at room temperature '); %25
q=1.6e-19;
k=1.38e-23;
t=a+273;
v=-0.2:0.01:0.25;
i=b*(exp(q*v/(k*t))-1);
plot(v,i)
xlabel('Voltage -->')
ylabel('Current -->')
grid on;
Plotting
DIFFERENT PLOT CODE FOR PRACTISE
Plotting
%%
x=[10:0.1:22];
y=95000./x.^2;
xd=[10:2:22];
yd=[950 640 460 340 250 180 140];
plot(x,y,'-','LineWidth',1.0)
hold on
plot(xd,yd,'ro--','linewidth',1.0,'markersize',10)
hold off
xlabel('DISTANCE (cm)')
ylabel('INTENSITY (lux)')
title('fontname{Arial}Light Intensity as a Function of Distance','FontSize',14)
axis([8 24 0 1200])
text(14,700,'Comparison between theory and experiment.','EdgeColor','r','LineWidth',2)
legend('Theory','Experiment',0)
%%
clear all;
x = randn(1,1000);
hist(x,100);
%%
figure(2);
t=-4:.1:4;
y = exp(-t.^2);
plot(t,y);
%%
t = 0:pi/20:2*pi;
x = sin(t);
y = cos(t);
figure(1);
plot(x);
figure(2);
plot(t,y);
figure(3);
plot(x,y);
DIFFERENT PLOT CODE FOR PRACTISE
Plotting
%%
sys = tf([2 5 1],[1 2 3]);
rlocus(sys)
sys = tf([0.5 -1],[4 0 3 0 2]);
k = (1:0.5:5);
r = rlocus(sys,k);
size(r)
rlocus(sys,k)
%%
[x,y] = meshgrid(-2:.1:2, -2:.1:2);
z = x.*exp(-x.^2 - y.^2);
mesh(z);
%%
%Matlab program to plot VI characteristics of a diode
clc;
close all;
clear all;
a=input('Enter the temperatre in degree centigrade ');
b=input('Enter the reverse saturation current at room temperature ');
q=1.6e-19;
k=1.38e-23;
t=a+273;
v=-0.2:0.01:0.25;
i=b*(exp(q*v/(k*t))-1);
plot(v,i)
xlabel('Voltage -->')
ylabel('Current -->')
grid on;
THANK YOU
Image Source
searchenterpriseai.techtarget.com
wikipedia

More Related Content

What's hot

Octave - Prototyping Machine Learning Algorithms
Octave - Prototyping Machine Learning AlgorithmsOctave - Prototyping Machine Learning Algorithms
Octave - Prototyping Machine Learning AlgorithmsCraig Trim
 
Matlab solved problems
Matlab solved problemsMatlab solved problems
Matlab solved problemsMake Mannan
 
Matlab practice
Matlab practiceMatlab practice
Matlab practiceZunAib Ali
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arraysAmeen San
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Palak Sanghani
 
Matlab 1
Matlab 1Matlab 1
Matlab 1asguna
 
Sample presentation slides template
Sample presentation slides templateSample presentation slides template
Sample presentation slides templateValerii Klymchuk
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical ComputingNaveed Rehman
 
MATLAB - Aplication of Arrays and Matrices in Electrical Systems
MATLAB - Aplication of Arrays and Matrices in Electrical SystemsMATLAB - Aplication of Arrays and Matrices in Electrical Systems
MATLAB - Aplication of Arrays and Matrices in Electrical SystemsShameer Ahmed Koya
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentationManchireddy Reddy
 

What's hot (20)

2D Plot Matlab
2D Plot Matlab2D Plot Matlab
2D Plot Matlab
 
Matlab lec1
Matlab lec1Matlab lec1
Matlab lec1
 
Octave - Prototyping Machine Learning Algorithms
Octave - Prototyping Machine Learning AlgorithmsOctave - Prototyping Machine Learning Algorithms
Octave - Prototyping Machine Learning Algorithms
 
Matlab solved problems
Matlab solved problemsMatlab solved problems
Matlab solved problems
 
Matlab practice
Matlab practiceMatlab practice
Matlab practice
 
Matlab matrices and arrays
Matlab matrices and arraysMatlab matrices and arrays
Matlab matrices and arrays
 
matlab
matlabmatlab
matlab
 
MATLAB - Arrays and Matrices
MATLAB - Arrays and MatricesMATLAB - Arrays and Matrices
MATLAB - Arrays and Matrices
 
Matlab Tutorial
Matlab TutorialMatlab Tutorial
Matlab Tutorial
 
Matlab introduction
Matlab introductionMatlab introduction
Matlab introduction
 
Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]Lec 9 05_sept [compatibility mode]
Lec 9 05_sept [compatibility mode]
 
Matlab 1
Matlab 1Matlab 1
Matlab 1
 
Sample presentation slides template
Sample presentation slides templateSample presentation slides template
Sample presentation slides template
 
Introduction to matlab
Introduction to matlabIntroduction to matlab
Introduction to matlab
 
MATLAB for Technical Computing
MATLAB for Technical ComputingMATLAB for Technical Computing
MATLAB for Technical Computing
 
Matlab differential
Matlab differentialMatlab differential
Matlab differential
 
Mat lab
Mat labMat lab
Mat lab
 
Tutorial 2
Tutorial     2Tutorial     2
Tutorial 2
 
MATLAB - Aplication of Arrays and Matrices in Electrical Systems
MATLAB - Aplication of Arrays and Matrices in Electrical SystemsMATLAB - Aplication of Arrays and Matrices in Electrical Systems
MATLAB - Aplication of Arrays and Matrices in Electrical Systems
 
B61301007 matlab documentation
B61301007 matlab documentationB61301007 matlab documentation
B61301007 matlab documentation
 

Similar to Programming with matlab session 6

Explanation on Tensorflow example -Deep mnist for expert
Explanation on Tensorflow example -Deep mnist for expertExplanation on Tensorflow example -Deep mnist for expert
Explanation on Tensorflow example -Deep mnist for expert홍배 김
 
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.docxgilpinleeanna
 
Lectures r-graphics
Lectures r-graphicsLectures r-graphics
Lectures r-graphicsetyca
 
17, r) -,r I -l19.t... 121.2t-314 23. ^t -rr - .docx
17, r) -,r I  -l19.t... 121.2t-314 23. ^t -rr - .docx17, r) -,r I  -l19.t... 121.2t-314 23. ^t -rr - .docx
17, r) -,r I -l19.t... 121.2t-314 23. ^t -rr - .docxhyacinthshackley2629
 
Matlab ch1 (6)
Matlab ch1 (6)Matlab ch1 (6)
Matlab ch1 (6)mohsinggg
 
COMPANION TO MATRICES SESSION III.pptx
COMPANION TO MATRICES SESSION III.pptxCOMPANION TO MATRICES SESSION III.pptx
COMPANION TO MATRICES SESSION III.pptximman gwu
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..Kamarudheen KV
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMohd Esa
 
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
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxIndhuMcamphil
 

Similar to Programming with matlab session 6 (20)

Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
Lesson 3
Lesson 3Lesson 3
Lesson 3
 
Lecture_3.pptx
Lecture_3.pptxLecture_3.pptx
Lecture_3.pptx
 
lect.no.3.pptx
lect.no.3.pptxlect.no.3.pptx
lect.no.3.pptx
 
MATLABgraphPlotting.pptx
MATLABgraphPlotting.pptxMATLABgraphPlotting.pptx
MATLABgraphPlotting.pptx
 
raster algorithm.pdf
raster algorithm.pdfraster algorithm.pdf
raster algorithm.pdf
 
Explanation on Tensorflow example -Deep mnist for expert
Explanation on Tensorflow example -Deep mnist for expertExplanation on Tensorflow example -Deep mnist for expert
Explanation on Tensorflow example -Deep mnist for expert
 
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
 
Introduction to r
Introduction to rIntroduction to r
Introduction to r
 
Lectures r-graphics
Lectures r-graphicsLectures r-graphics
Lectures r-graphics
 
17, r) -,r I -l19.t... 121.2t-314 23. ^t -rr - .docx
17, r) -,r I  -l19.t... 121.2t-314 23. ^t -rr - .docx17, r) -,r I  -l19.t... 121.2t-314 23. ^t -rr - .docx
17, r) -,r I -l19.t... 121.2t-314 23. ^t -rr - .docx
 
Matlab ch1 (6)
Matlab ch1 (6)Matlab ch1 (6)
Matlab ch1 (6)
 
R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 
COMPANION TO MATRICES SESSION III.pptx
COMPANION TO MATRICES SESSION III.pptxCOMPANION TO MATRICES SESSION III.pptx
COMPANION TO MATRICES SESSION III.pptx
 
statistical computation using R- an intro..
statistical computation using R- an intro..statistical computation using R- an intro..
statistical computation using R- an intro..
 
Graph Plots in Matlab
Graph Plots in MatlabGraph Plots in Matlab
Graph Plots in Matlab
 
Matlab: Graph Plots
Matlab: Graph PlotsMatlab: Graph Plots
Matlab: Graph Plots
 
Matlab-free course by Mohd Esa
Matlab-free course by Mohd EsaMatlab-free course by Mohd Esa
Matlab-free course by Mohd Esa
 
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
 
OUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptxOUTPUT PRIMITIVES.pptx
OUTPUT PRIMITIVES.pptx
 

More from Infinity Tech Solutions

Database Management System-session 3-4-5
Database Management System-session 3-4-5Database Management System-session 3-4-5
Database Management System-session 3-4-5Infinity Tech Solutions
 
Main topic 3 problem solving and office automation
Main topic 3 problem solving and office automationMain topic 3 problem solving and office automation
Main topic 3 problem solving and office automationInfinity Tech Solutions
 
Computer memory, Types of programming languages
Computer memory, Types of programming languagesComputer memory, Types of programming languages
Computer memory, Types of programming languagesInfinity Tech Solutions
 
AI/ML/DL/BCT A Revolution in Maritime Sector
AI/ML/DL/BCT A Revolution in Maritime SectorAI/ML/DL/BCT A Revolution in Maritime Sector
AI/ML/DL/BCT A Revolution in Maritime SectorInfinity Tech Solutions
 
Programming with matlab session 5 looping
Programming with matlab session 5 loopingProgramming with matlab session 5 looping
Programming with matlab session 5 loopingInfinity Tech Solutions
 

More from Infinity Tech Solutions (20)

Database management system session 6
Database management system session 6Database management system session 6
Database management system session 6
 
Database management system session 5
Database management system session 5Database management system session 5
Database management system session 5
 
Database Management System-session 3-4-5
Database Management System-session 3-4-5Database Management System-session 3-4-5
Database Management System-session 3-4-5
 
Database Management System-session1-2
Database Management System-session1-2Database Management System-session1-2
Database Management System-session1-2
 
Main topic 3 problem solving and office automation
Main topic 3 problem solving and office automationMain topic 3 problem solving and office automation
Main topic 3 problem solving and office automation
 
Introduction to c programming
Introduction to c programmingIntroduction to c programming
Introduction to c programming
 
E commerce
E commerce E commerce
E commerce
 
E commerce
E commerceE commerce
E commerce
 
Bds session 13 14
Bds session 13 14Bds session 13 14
Bds session 13 14
 
Computer memory, Types of programming languages
Computer memory, Types of programming languagesComputer memory, Types of programming languages
Computer memory, Types of programming languages
 
Basic hardware familiarization
Basic hardware familiarizationBasic hardware familiarization
Basic hardware familiarization
 
User defined functions in matlab
User defined functions in  matlabUser defined functions in  matlab
User defined functions in matlab
 
Programming with matlab session 3 notes
Programming with matlab session 3 notesProgramming with matlab session 3 notes
Programming with matlab session 3 notes
 
AI/ML/DL/BCT A Revolution in Maritime Sector
AI/ML/DL/BCT A Revolution in Maritime SectorAI/ML/DL/BCT A Revolution in Maritime Sector
AI/ML/DL/BCT A Revolution in Maritime Sector
 
Programming with matlab session 5 looping
Programming with matlab session 5 loopingProgramming with matlab session 5 looping
Programming with matlab session 5 looping
 
BIG DATA Session 7 8
BIG DATA Session 7 8BIG DATA Session 7 8
BIG DATA Session 7 8
 
BIG DATA Session 6
BIG DATA Session 6BIG DATA Session 6
BIG DATA Session 6
 
MS word
MS word MS word
MS word
 
DBMS CS 4-5
DBMS CS 4-5DBMS CS 4-5
DBMS CS 4-5
 
DBMS CS3
DBMS CS3DBMS CS3
DBMS CS3
 

Recently uploaded

MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSSIVASHANKAR N
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSISrknatarajan
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
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
 
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
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
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
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝soniya singh
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130Suhani Kapoor
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...ranjana rawat
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations120cr0395
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxpurnimasatapathy1234
 
(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
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Christo Ananth
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
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)

MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLSMANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
MANUFACTURING PROCESS-II UNIT-5 NC MACHINE TOOLS
 
UNIT-III FMM. DIMENSIONAL ANALYSIS
UNIT-III FMM.        DIMENSIONAL ANALYSISUNIT-III FMM.        DIMENSIONAL ANALYSIS
UNIT-III FMM. DIMENSIONAL ANALYSIS
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
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 Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
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
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
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
 
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
Model Call Girl in Narela Delhi reach out to us at 🔝8264348440🔝
 
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
VIP Call Girls Service Hitech City Hyderabad Call +91-8250192130
 
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
(TARA) Talegaon Dabhade Call Girls Just Call 7001035870 [ Cash on Delivery ] ...
 
Extrusion Processes and Their Limitations
Extrusion Processes and Their LimitationsExtrusion Processes and Their Limitations
Extrusion Processes and Their Limitations
 
Microscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptxMicroscopic Analysis of Ceramic Materials.pptx
Microscopic Analysis of Ceramic Materials.pptx
 
(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...
 
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
Call for Papers - African Journal of Biological Sciences, E-ISSN: 2663-2187, ...
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
Call Girls in Nagpur Suman Call 7001035870 Meet With Nagpur Escorts
 
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
 

Programming with matlab session 6

  • 2. Session objective Introdcution Plotting basic 2-D plots. The plot command The fplot command Plotting multiple graphs in the same plot Formatting plots SUMMARY
  • 3. MAKING X-Y PLOTS MATLAB has many functions and commands that can be used to create various types of plots. In our class we will only create two dimensional x – y plots.
  • 4. 8 10 12 14 16 18 20 22 24 0 200 400 600 800 1000 1200 DISTANCE (cm) INTENSITY(lux) Light Intensity as a Function of Distance Comparison between theory and experiment. Theory Experiment Plot title y axis label x axis label Text Tick-mark label EXAMPLE OF A 2-D PLOT Data symbol Legend Tick-mark Plotting
  • 5. TWO-DIMENSIONAL plot() COMMAND where x is a vector (one dimensional array), and y is a vector. Both vectors must have the same number of elements.  The plot command creates a single curve with the x values on the abscissa (horizontal axis) and the y values on the ordinate (vertical axis).  The curve is made from segments of lines that connect the points that are defined by the x and y coordinates of the elements in the two vectors. The basic 2-D plot command is: plot(x,y) Plotting
  • 6.  If data is given, the information is entered as the elements of the vectors x and y.  If the values of y are determined by a function from the values of x, than a vector x is created first, and then the values of y are calculated for each value of x. The spacing (difference) between the elements of x must be such that the plotted curve will show the details of the function. CREATING THE X AND Y VECTORS Plotting
  • 7. PLOT OF GIVEN DATA Given data: >> x=[1 2 3 5 7 7.5 8 10]; >> y=[2 6.5 7 7 5.5 4 6 8]; >> plot(x,y) A plot can be created by the commands shown below. This can be done in the Command Window, or by writing and then running a script file. Once the plot command is executed, the Figure Window opens with the following plot. x y 1 2 3 5 7 7.5 8 6.5 7 7 5.5 4 6 8 10 2 Plotting
  • 8. PLOT OF GIVEN DATA Plotting
  • 9. LINE SPECIFIERS IN THE plot() COMMAND Line specifiers can be added in the plot command to:  Specify the style of the line.  Specify the color of the line.  Specify the type of the markers (if markers are desired). plot(x,y,’line specifiers’) Plotting
  • 10. LINE SPECIFIERS IN THE plot() COMMAND Line Specifier Line Specifier Marker Specifier Style Color Type Solid - red r plus sign + dotted : green g circle o dashed -- blue b asterisk * dash-dot -. Cyan c point . magenta m square s yellow y diamond d black k plot(x,y,‘line specifiers’) Plotting
  • 11. LINE SPECIFIERS IN THE plot() COMMAND  The specifiers are typed inside the plot() command as strings.  Within the string the specifiers can be typed in any order.  The specifiers are optional. This means that none, one, two, or all the three can be included in a command. EXAMPLES: plot(x,y) A solid blue line connects the points with no markers. plot(x,y,’r’) A solid red line connects the points with no markers. plot(x,y,’--y’) A yellow dashed line connects the points. plot(x,y,’*’) The points are marked with * (no line between the points.) plot(x,y,’g:d’) A green dotted line connects the points which are marked with diamond markers. Plotting
  • 12. Year Sales (M) 1988 1989 1990 1991 1992 1993 1994 127 130 136 145 158 178 211 PLOT OF GIVEN DATA USING LINE SPECIFIERS IN THE plot() COMMAND >> year = [1988:1:1994]; >> sales = [127, 130, 136, 145, 158, 178, 211]; >> plot(year,sales,'--r*') Line Specifiers: dashed red line and asterisk markers. Plotting
  • 13. PLOT OF GIVEN DATA USING LINE SPECIFIERS IN THE plot() COMMAND Dashed red line and asterisk markers. Plotting
  • 14. PLOT OF GIVEN DATA USING LINE SPECIFIERS IN THE plot() COMMAND Dashed red line and asterisk markers. Plotting
  • 15. % A script file that creates a plot of % the function: 3.5^(-0.5x)*cos(6x) x = [-2:0.01:4]; y = 3.5.^(-0.5*x).*cos(6*x); plot(x,y) CREATING A PLOT OF A FUNCTION Consider: 42for)6cos(5.3 5.0   xxy x A script file for plotting the function is: Creating a vector with spacing of 0.01. Calculating a value of y for each x. Once the plot command is executed, the Figure Window opens with the following plot. Plotting
  • 16. A PLOT OF A FUNCTION 42for)6cos(5.3 5.0   xxy x Plotting
  • 17. CREATING A PLOT OF A FUNCTION If the vector x is created with large spacing, the graph is not accurate. Below is the previous plot with spacing of 0.3. x = [-2:0.3:4]; y = 3.5.^(-0.5*x).*cos(6*x); plot(x,y) Plotting
  • 18. THE fplot COMMAND fplot(‘function’,limits) The fplot command can be used to plot a function with the form: y = f(x)  The function is typed in as a string.  The limits is a vector with the domain of x, and optionally with limits of the y axis: [xmin,xmax] or [xmin,xmax,ymin,ymax]  Line specifiers can be added. Plotting
  • 19. PLOT OF A FUNCTION WITH THE fplot() COMMAND >> fplot('x^2 + 4 * sin(2*x) - 1', [-3 3]) 33for1)2sin(42  xxxyA plot of: Plotting
  • 20. PLOTTING MULTIPLE GRAPHS IN THE SAME PLOT Plotting two (or more) graphs in one plot: 1. Using the plot command. 2. Using the hold on, hold off commands. Plotting
  • 21. USING THE plot() COMMAND TO PLOT MULTIPLE GRAPHS IN THE SAME PLOT Plots three graphs in the same plot: y versus x, v versus u, and h versus t.  By default, MATLAB makes the curves in different colors.  Additional curves can be added.  The curves can have a specific style by adding specifiers after each pair, for example: plot(x,y,u,v,t,h) plot(x,y,’-b’,u,v,’—r’,t,h,’g:’) Plotting
  • 22. USING THE plot() COMMAND TO PLOT MULTIPLE GRAPHS IN THE SAME PLOT 42  x Plot of the function, and its first and second derivatives, for , all in the same plot. 10263 3  xxy 42  x x = [-2:0.01:4]; y = 3*x.^3-26*x+6; yd = 9*x.^2-26; ydd = 18*x; plot(x,y,'-b',x,yd,'--r',x,ydd,':k') vector x with the domain of the function. Vector y with the function value at each x. 42  x Vector yd with values of the first derivative. Vector ydd with values of the second derivative. Create three graphs, y vs. x (solid blue line), yd vs. x (dashed red line), and ydd vs. x (dotted black line) in the same figure. Plotting
  • 23. -2 -1 0 1 2 3 4 -40 -20 0 20 40 60 80 100 120 USING THE plot() COMMAND TO PLOT MULTIPLE GRAPHS IN THE SAME PLOT Plotting
  • 24. hold on Holds the current plot and all axis properties so that subsequent plot commands add to the existing plot. hold off Returns to the default mode whereby plot commands erase the previous plots and reset all axis properties before drawing new plots. USING THE hold on, hold off, COMMANDS TO PLOT MULTIPLE GRAPHS IN THE SAME PLOT This method is useful when all the information (vectors) used for the plotting is not available a the same time. Plotting
  • 25. Plot of the function, and its first and second derivatives, for all in the same plot. 10263 3  xxy 42  x x = [-2:0.01:4]; y = 3*x.^3-26*x+6; yd = 9*x.^2-26; ydd = 18*x; plot(x,y,'-b') hold on plot(x,yd,'--r') plot(x,ydd,':k') hold off Two more graphs are created. First graph is created. USING THE hold on, hold off, COMMANDS TO PLOT MULTIPLE GRAPHS IN THE SAME PLOT Plotting
  • 26. 8 10 12 14 16 18 20 22 24 0 200 400 600 800 1000 1200 DISTANCE (cm) INTENSITY(lux) Light Intensity as a Function of Distance Comparison between theory and experiment. Theory Experiment Plot title y axis label x axis label Text EXAMPLE OF A FORMATTED 2-D PLOT Data symbol Legend Tick-mark Tick-mark label Plotting
  • 27. FORMATTING PLOTS A plot can be formatted to have a required appearance. With formatting you can:  Add title to the plot.  Add labels to axes.  Change range of the axes.  Add legend.  Add text blocks.  Add grid. Plotting
  • 28. FORMATTING PLOTS There are two methods to format a plot: 1. Formatting commands. In this method commands, that make changes or additions to the plot, are entered after the plot() command. This can be done in the Command Window, or as part of a program in a script file. 2. Formatting the plot interactively in the Figure Window. In this method the plot is formatted by clicking on the plot and using the menu to make changes or add details. Plotting
  • 29. FORMATTING COMMANDS title(‘string’) Adds the string as a title at the top of the plot. xlabel(‘string’) Adds the string as a label to the x-axis. ylabel(‘string’) Adds the string as a label to the y-axis. axis([xmin xmax ymin ymax]) Sets the minimum and maximum limits of the x- and y-axes. Plotting
  • 30. FORMATTING COMMANDS legend(‘string1’,’string2’,’string3’) Creates a legend using the strings to label various curves (when several curves are in one plot). The location of the legend is specified by the mouse. text(x,y,’string’) Places the string (text) on the plot at coordinate x,y relative to the plot axes. gtext(‘string’) Places the string (text) on the plot. When the command executes the figure window pops and the text location is clicked with the mouse. Plotting
  • 31. EXAMPLE OF A FORMATTED PLOT Below is a script file of the formatted light intensity plot (2nd slide). (Some of the formatting options were not covered in the lectures, but are described in the book) x=[10:0.1:22]; y=95000./x.^2; xd=[10:2:22]; yd=[950 640 460 340 250 180 140]; plot(x,y,'-','LineWidth',1.0) hold on plot(xd,yd,'ro--','linewidth',1.0,'markersize',10) hold off Creating a vector with light intensity from data. Creating a vector with coordinates of data points. Creating vector x for plotting the theoretical curve. Creating vector y for plotting the theoretical curve. Plotting
  • 32. EXAMPLE OF A FORMATTED PLOT Formatting of the light intensity plot (cont.) xlabel('DISTANCE (cm)') ylabel('INTENSITY (lux)') title('fontname{Arial}Light Intensity as a Function of Distance','FontSize',14) axis([8 24 0 1200]) text(14,700,'Comparison between theory and experiment.','EdgeColor','r','LineWidth',2) legend('Theory','Experiment',0) Creating text. Creating a legend. Title for the plot. Setting limits of the axes. Labels for the axes. The plot that is obtained is shown again in the next slide. Plotting
  • 33. EXAMPLE OF A FORMATTED PLOT Plotting
  • 34. FORMATTING A PLOT IN THE FIGURE WINDOW Once a figure window is open, the figure can be formatted interactively. Use Figure, Axes, and Current Object- Properties in the Edit menu Click here to start the plot edit mode. Use the insert menu to Plotting
  • 35. MATLAB PROGRAM TO PLOT VI CHARACTERISTICS OF A DIODE %Matlab program to plot VI characteristics of a diode clc; close all; clear all; a=input('Enter the temperatre in degree centigrade '); %40 b=input('Enter the reverse saturation current at room temperature '); %25 q=1.6e-19; k=1.38e-23; t=a+273; v=-0.2:0.01:0.25; i=b*(exp(q*v/(k*t))-1); plot(v,i) xlabel('Voltage -->') ylabel('Current -->') grid on; Plotting
  • 36. DIFFERENT PLOT CODE FOR PRACTISE Plotting %% x=[10:0.1:22]; y=95000./x.^2; xd=[10:2:22]; yd=[950 640 460 340 250 180 140]; plot(x,y,'-','LineWidth',1.0) hold on plot(xd,yd,'ro--','linewidth',1.0,'markersize',10) hold off xlabel('DISTANCE (cm)') ylabel('INTENSITY (lux)') title('fontname{Arial}Light Intensity as a Function of Distance','FontSize',14) axis([8 24 0 1200]) text(14,700,'Comparison between theory and experiment.','EdgeColor','r','LineWidth',2) legend('Theory','Experiment',0) %% clear all; x = randn(1,1000); hist(x,100); %% figure(2); t=-4:.1:4; y = exp(-t.^2); plot(t,y); %% t = 0:pi/20:2*pi; x = sin(t); y = cos(t); figure(1); plot(x); figure(2); plot(t,y); figure(3); plot(x,y);
  • 37. DIFFERENT PLOT CODE FOR PRACTISE Plotting %% sys = tf([2 5 1],[1 2 3]); rlocus(sys) sys = tf([0.5 -1],[4 0 3 0 2]); k = (1:0.5:5); r = rlocus(sys,k); size(r) rlocus(sys,k) %% [x,y] = meshgrid(-2:.1:2, -2:.1:2); z = x.*exp(-x.^2 - y.^2); mesh(z); %% %Matlab program to plot VI characteristics of a diode clc; close all; clear all; a=input('Enter the temperatre in degree centigrade '); b=input('Enter the reverse saturation current at room temperature '); q=1.6e-19; k=1.38e-23; t=a+273; v=-0.2:0.01:0.25; i=b*(exp(q*v/(k*t))-1); plot(v,i) xlabel('Voltage -->') ylabel('Current -->') grid on;