Matlab Graph & Plotting
Matlab Graph & Plotting
PDPM
Indian Institute of Information Technology,
Design and Manufacturing Jabalpur
Experiment-2
MATLAB Graph & plotting
Overview
• MATLAB has an excellent set of graphic tools.
• Being able to plot mathematical functions and data freely is the most
important step, and this section is written to assist you to do just that.
Two Dimensional Plots(2D plots)
Command : plot(x,y) or plot (abscissa, ordinate)
Example: Plot sine function for two cycles.
t=0:pi/200:4*pi;
y=sin(t);
plot(t,y)
Two Dimensional Plots(2D plots)
Adding titles and axis labels: MATLAB also allows labelling of axes.
i.e. x,y axes and title.
Command : xlabel(‘string’)
xlabel() function allows to label the x-axis
Command : ylabel(‘string’)
ylabel() function allows to label the y-axis
Command: title(‘string’)
title()– function allows giving title to our plot.
Note : The order of the xlabel, ylabel, and title commands does not
matter, but we must place them after the plot command.
Two Dimensional Plots(2D plots)
Line styles, Markers and Colours:
Various line types, plot symbols and colors may be obtained with
plot(x,y,s) where s is a character string made from one element from
any or all the following 3 columns given below.
• Command: gtext(‘text’)
Places the string text in the Figure
window at a point specified by the
mouse.
Two Dimensional Plots(2D plots)
Create chart with two y-axes
• Command: yyaxis left
yyaxis right
Two Dimensional Plots(2D plots)
Specialized plot commands
Two Dimensional Plots(2D plots)
•
Two Dimensional Plots(2D plots)
Box plot
Command: boxplot(x)
• boxplot(x) creates a box plot of the data in x. If x is a vector, boxplot
plots one box. If x is a matrix, boxplot plots one box for each column
of x.
• On each box, the central mark indicates the median, and the bottom
and top edges of the box indicate the 25th and 75th percentiles,
respectively.
• The whiskers extend to the most extreme data points not considered
outliers, and the outliers are plotted individually using the '+' marker
symbol.
Two Dimensional Plots(2D plots)
Note: Each box visually represents the MPG data for cars from the specified country. Italy's "box"
appears as a single line because the sample data contains only one observation for this group
Trigonometry function
• The trigonometric functions in MATLAB calculate standard
trigonometric values in radians or degrees, hyperbolic trigonometric
values in radians, and inverse variants of each function.
• You can use the rad2deg and deg2rad functions to convert between
radians and degrees, or functions like cart2pol to convert between
coordinate systems.
Coordinate Conversion
Transform Cartesian coordinates to polar or
cart2pol
cylindrical
cart2sph Transform Cartesian coordinates to spherical
Transform polar or cylindrical coordinates to
pol2cart
Cartesian
sph2cart Transform spherical coordinates to Cartesian
Complex Numbers
• In MATLAB, i and j represent the basic imaginary unit. You can use
them to create complex numbers such as 2i+5.
• You can also determine the real and imaginary parts of complex
numbers and compute other common values such as phase and angle.
Basic commands:
abs Absolute value and complex magnitude
angle Phase angle
complex Create complex array
conj Complex conjugate
cplxpair Sort complex numbers into complex conjugate pairs
i Imaginary unit
imag Imaginary part of complex number
isreal Determine whether array uses complex storage
j Imaginary unit
real Real part of complex number
Test Your Understanding
•
Test Your Understanding