0% found this document useful (0 votes)
27 views21 pages

Matlab Graph & Plotting

This document provides an overview of graphing and plotting capabilities in MATLAB. It discusses how to create 2D plots using the plot command and customize plots by adding titles, labels, legends and changing line styles. It also describes how to plot multiple datasets on the same graph using hold on/off or subplot, and specialized plot types like boxplots. The document concludes with brief explanations of trigonometric functions, complex numbers and coordinate system conversions in MATLAB.

Uploaded by

karlapuditharun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views21 pages

Matlab Graph & Plotting

This document provides an overview of graphing and plotting capabilities in MATLAB. It discusses how to create 2D plots using the plot command and customize plots by adding titles, labels, legends and changing line styles. It also describes how to plot multiple datasets on the same graph using hold on/off or subplot, and specialized plot types like boxplots. The document concludes with brief explanations of trigonometric functions, complex numbers and coordinate system conversions in MATLAB.

Uploaded by

karlapuditharun
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Experiment-2

Trigonometric Function, Complex Numbers & M Files in


MATLAB/ Graph & Plotting in MATLAB

Mr. Kumar Prabhakar


Electronics & Communication Engineering

PDPM
Indian Institute of Information Technology,
Design and Manufacturing Jabalpur
Experiment-2
MATLAB Graph & plotting
Overview
• MATLAB has an excellent set of graphic tools.

• Plotting a given data set or the results of computation is possible with


very few commands.

• Understanding of mathematical equations with graphics is an


enjoyable and very efficient way of learning mathematics

• 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.

Note : Default colour of graph is blue


Two Dimensional Plots(2D plots)
Controlling Axes
• The scaling and appearance of plot axis can be controlled with the axis
function. To set scaling for the x and y axes on the current 2-D plot,
use the below given command:

Command: axis([xmin xmax ymin ymax])


• Others use full command for axis controlling are:
Command: axis('auto’); axis('square’) ; axis('off ‘) ; axis(tight);
axis(equal)
Two Dimensional Plots(2D plots)
Multiple data sets in one plot
• Many times you may have to plot many functions in different figures
or multiple functions in the same figure. The following piece of code
is an initial attempt to create many plots together.
• For example, these statements plot three related functions of t: y1 = 2*
cos(t), y2 = cos(t), y3 = 0.5 ∗ cos(t), and y4=sin(t) in the interval 0 ≤ t
≤ 2π.
✔ Using single plot command

✔ Using multiple plot commands [hold on hold off]


Two Dimensional Plots(2D plots)
Subplotting
• Sometimes creating a single plot for several functions is not practical
due to different scales and units of the functions.
• Science and Engineering applications, often it is desirable to visualize
many functions together, and subplot command can easily serve the
purpose in place of having many different plots and trying to bring
them together.
Example: The average yearly rainfall and production of rice in a
particular state is given by the following table for 7 consecutive years:
Two Dimensional Plots(2D plots)
• The subplot command allows you to separate the figure into as many
plots as desired, and arrange them all in one figure.
• The general format of this command is : subplot(m,n,p)
Two Dimensional Plots(2D plots)
Create chart with two y-axes
• Command: plotyy(x1,y1,x2,y2)
Produces a plot with two y axes, y1 on the left and y2 on the right

• 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.

sin Sine of argument in radians cos Cosine of argument in radians


sind Sine of argument in degrees cosd Cosine of argument in degrees
sinpi Compute sin(X*pi) accurately cospi Compute cos(X*pi) accurately
asin Inverse sine in radians acos Inverse cosine in radians
asind Inverse sine in degrees acosd Inverse cosine in degrees
sinh Hyperbolic sine cosh Hyperbolic cosine
asinh Inverse hyperbolic sine acosh Inverse hyperbolic cosine
Trigonometry function
tan Tangent of argument in radians csc Cosecant of input angle in radians
tand Tangent of argument in degrees cscd Cosecant of argument in degrees
atan Inverse tangent in radians acsc Inverse cosecant in radians
atand Inverse tangent in degrees acscd Inverse cosecant in degrees
atan2 Four-quadrant inverse tangent csch Hyperbolic cosecant
atan2d Four-quadrant inverse tangent in degrees acsch Inverse hyperbolic cosecant
tanh Hyperbolic tangent sec Secant of angle in radians
atanh Inverse hyperbolic tangent secd Secant of argument in degrees
asec Inverse secant in radians
asecd Inverse secant in degrees
sech Hyperbolic secant
asech Inverse hyperbolic secant
Degrees/Radians Conversion and Coordinate
Conversion
Degrees/Radians Conversion
deg2rad Convert angle from degrees to radians
rad2deg Convert angle from radians to degrees

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

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy