Matlab 6
Matlab 6
PLOTTING
To plot the graph of a function, you need to take
the following steps:
Define x, by specifying the range of values for the
variable x, for which the function is to be plotted
Define the function, y = f(x)
Call the plot command, as plot(x, y)
For example: Plot y= x
• x = [0:5:100];
• y = x;
• plot(x, y)
Adding Title, Labels, Grid Lines, and
Scaling on the Graph
• MATLAB allows you to 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 you to put a title on
the graph.
• The grid on command allows you to put the grid
lines on the graph.
• The axis equal command allows generating the
plot with the same scale factors and the spaces
on both axes.
– title(‘this is the title’)
– xlabel(‘x’)
– ylabel(‘y’)
Example
• x = [0:0.01:10];
• y = sin(x);
• plot(x, y), xlabel('x'), ylabel('Sin(x)'),
title('Sin(x) Graph'),
• grid on, axis equal
Line Style Description