Matlab - Graphs Tutorials
Matlab - Graphs Tutorials
GRAPHS TUTORIALS
Table of Contents
·Basic Overview
.Syntax
.Labeling Axes
.Legends
.Manipulating Axes
.Subplots
.Multiple Y-Axes
.Statistics
.3-D plots
Why use MATLAB to create
graphs?
One single programme to process data and
plot results:
Transfer errors are less likely
Every step of analysis and plotting is well
documented
One button click can re-create the final
graphs if the data change
Graphs can be (re-)created in every image
format and print resolution
Basic Overview
To use the ‘plot’ function in Matlab, you
should first make sure that the
matrices/vectors
you are trying to use are of equal
dimensions. For example, if I wanted to
plot vector X = [3 9
27] over time, my vector for time would
also need to be a 1x3 vector (i.e. t = [1 2
3]).
BASIC PLOTTING
COMMANDS
figure : creates a new figure window
plot(x) : plots line graph of x vs index
number of array
plot(x,y) : plots line graph of x vs y
plot(x,y,'r--')
: plots x vs y with linetype
specified in string : 'r' = red, 'g'=green,
etc for a limited set of basic
colours.
'' solid line, ' ' dashed, 'o'
circles…see graphics section of
helpdesk
Syntax
To plot the example vectors above in
a new figure:
clear all % clear all previous variables
X = [3 9 27]; % my dependent vector
of interest
t = [1 2 3]; % my independent vector
figure % create new figure
plot(t, X)
LABELING AXIS
>> subplot(2,3,1);
>> subplot(2,3,4); P1 P P3
2
P4
clear all
close all
% subplot (nrows,ncols,plot_number)
x=0:.1:2*pi; % x vector from 0 to 2*pi, dx = 0.1
subplot(2,2,1); % plot sine function
plot(x,sin(x));
subplot(2,2,2); % plot cosine function
plot(x,cos(x));
subplot(2,2,3) % plot negative exponential function
plot(x,exp(-x));
subplot(2,2,4); % plot x^3
plot(x, x.^3);
PLOTTING IN 3D