% examples.m
% Just to play around with a little test file of MATLAB commands
% A. Harris 9/10/2012

% Set up access to A310 scripts 
addpath('~harris/a310')

% Look at a help file
help('mean')
help mean

% Make up a matrix and play around with it
A = [1,2,3;4,5,6;7,8,9];
A
mean(A)
sprintf('The mean mean is %5.3f', mean(mean(A)))
% Make another matrix in a different way, without the ; at the end
B = [2 2 2 
     3 3 3 
     1 1 1]
% Try matrix multiplication and element-by-element multiplication
 A*B
 A.*B
 
% Make an image, then write files of the image
imagesc(A) 
print -depsc2 newfig.eps  % an encapsulated postscript file -- gv to view
print -djpeg newfig.jpg   % a jpeg file -- gThumb to view

% A little loop to compute sums and means:
a = 1:10;
nsum = 5;
sum = 0;
for i=1:nsum
    sum = sum + a(i)  % no ;, so it will print each step
end
mean = sum/nsum 

% find sizes of matrices and vectors
length(a)
C = [1 2 3 
     4 5 6
     7 8 9
     1 2 3]
size(C)
length(C)
D = C' % matrix transpose
size(D)
length(D)