Professional Documents
Culture Documents
2-Dimensional Plots
The most common plot is the x-y plot
The data is in vectors (1-dimensional matrices) called
x and y
x – independent variable
y – dependent variable
Plotting Example Data
x = [1:10];
y = [58.5, 63.8, 64.2, 67.3, 71.5, 88.3, 90.1, 90.6,
89.5, 90.4];
t = 0:pi/100:2*pi;
y1 = cos(t*4);
plot(t,y1)
y2 = sin(t);
hold on;
plot(t,y2)
Plots will continue to layer until until you say “hold off”
Plotting Multiple Lines
Another way to create multiple lines is to request both
lines in a single “plot” command:
plot(X, Y, W, Z) % input is alternating
% x and y vectors
plot(x, y1, x, y2) % from previous example
Example:
plot(x,y,‘:ok’,x,y*2,‘--xr’,x,y/2,‘-b’)
subplot(2,3,2) subplot(2,3,5)
plot(x, cos(x)) plot(x, sqrt(x))
title(‘2 - cos(x)’); title(‘5 - sqrt(x)’);
subplot(2,3,3) subplot(2,3,6)
plot(x, tan(x)) plot(x, exp(x))
title(‘3 - tan(x)’); title(‘6 - exp(x)’);
subplot(2,3,4)
plot(x, x.^2)
title(‘4 – x^2’);
3-Dimensional Plots
The “plot3” function is similar to “plot”
The data is in vectors (1-dimensional matrices) called
x, y, and z
plot3(x, y, z)