Introduction Part Ii: Graphics in Matlab
Introduction Part Ii: Graphics in Matlab
Introduction Part Ii: Graphics in Matlab
Graphics in Matlab
Creating a Plot
The plot function can take one or more inputs;
e.g. plot (x, y) or plot (y)
To plot a sin/cos function, can use
x = 0:pi/100:2*pi; y = sin(x); plot(x,y)
To add title and labels to the plot
xlabel('x = 0:2\pi'); ylabel('Sine of x');
title('Plot of the Sine Function','FontSize',12)
Remember, >> help plot is always useful
Multiple Data Sets in One Graph
Multiple x-y pair arguments create multiple
graphs with a single call to plot
Example: x = 0:pi/100:2*pi; y = sin(x); y2 = sin(x-.25);
y3 = sin(x-.5); plot(x,y,x,y2,x,y3);
Legend command helps identify plots
legend('sin(x)','sin(x-.25)','sin(x-.5)');
>> help legend % more about legend uses
>> help title >> help xlabel >>help ylabel
Specifying Line Styles and Colours
It is possible to specify colour, line styles, and markers (such
as plus signs or circles) when you plot your data using the plot
command
plot (x, y, 'color_style_marker')
color_style_marker can be of:
Colour signs: 'c' 'r' 'y' 'g' 'b' 'w'
Line style strings: '-' for solid, '--' for dashed, ':' for dotted, '-.' for dash-dot
The marker types are '+', 'o', '*', and 'x', and the filled marker
types are 's' for square, 'd' for diamond, etc.
Imaginary and Complex Data
If Z is a complex number, then plot (Z) is the same as
plot (real (Z), imag (Z)); for example
t = 0:pi/10:2*pi; plot (exp(i*t),'-o'); axis equal
Sin Cos
Cot Tan