Plotting a Sine Wave
x = [0:.2:6]
y = sin(x)
plot(y)
This will plot the sine function you just saved to the variable y. Notice that it just plotted the values of y versus the index of each data point (from 1 to 31).
This is a basic 2D plot. You can see a list of all the 2D plots available by typing help graph2d.
plot(x,y)
grid on % adds grid
Now we have the proper x-values along the bottom axis.
*If your plot window gets hidden, you can bring it to the front with 'figure(1)', which tells Matlab to make figure #1 active, or with 'figure(gcf)', which gets the handle for the current figure (gcf = 'get current figure'), and makes it active. If you give Matlab a figure number that does not exist, it will open a new figure with that handle.
A = [x;x];
surf(sin(A)) % 3D plot
You can see a list of all the 3D plots available by typing help graph3d (and also get a list of available colormaps).
figure % open a new figure
surf(sin(A')) % an apostrophe transposes the matrix A
B = repmat(x,[31 1]); % creates a 31x31 matrix by replicating x, a 1x31 matrix, 31x1 times
figure
surf(sin(B) + sin(B')) % the interference pattern of two orthogonal sine waves
colorbar % values of color axis
xlabel('x'); ylabel('y'); zlabel('z'); % label the axes. note we can combine multiple commands on one line