% This file demonstrates some of Matlab's basic matrix and
% vector manipulation and plotting features.
%
% P. Fieguth, January 1997
%
% Sources of additional information:
% Matlab's reference manual
% Matlab help:
% For help on any function, type "help functionname"
% For example, "help eig" gives help on Matlab's eigenvalue function.
%
%
% Basic Matrix definitions
%
% Matrices entered row by row; use semicolon to separate rows:
% Variable names can be upper or lower case; case is significant.
A = [1 2 3 ; 4 4 4 ; 1 4 9];
% Any statement ending in a semicolon is not printed, otherwise the result
% is displayed, e.g.
B = A;
C = A
% Can access elements or subsets of matrices;
% A colon ":" implies a whole row or column
A(1,2)
A(2,:)
A(:,3)
A(1:2,2:3)
% Transpose is "'", matrix inverse is "inv", determinant is "det"
A'
inv(A)
det(A)
% Regular matrix multiplication is *; element-by-element multiplication is .*
A * A
A .* A
A + A
% Matlab has a wide variety of plotting methods, use "help plot" to find
% out more. Plot types include 3-D mesh and surface plots and more.
x = [10:20];
y = x .* x;
% Basic line plot, default x-axis
plot(y);
% Basic line plot, user-specified x-axis
plot(x,y);
% Basic line plot, user specified symbol
plot(x,y,'+');
% The currently "active" figure (the one you just plotted to)
% can be printed to a postscript file as follows
print -dps testplot.ps
% You would then issue the usual plot command to print the postscript
% file to whichever laser printer you use.
% User-defined functions: you can define your own function, see
% the file demofunc372.m for an example. We'll use that function here:
help demofunc372
v = demofunc372(x)
v = demofunc372(y)
v = demofunc372(x,y)
% The Matlab session is ended by typing "quit"
% Finally, a handy function is "whos", which lists all of your variables
whos