MATLAB TUTORIAL AND NOTES (1) (2):
1) BASICS:
>> pwd
>> cd
>> ls
>> whos
>> path
Matlab History:


Example:
>> w
>> whos
Element-wise op's
>> a./b vs a/b
>> a.*b vs a*b
>> a.^b vs a^b
Important Syntax:
':'
';'
'[ ]'
'( )'
Print working directory (this tells you which directory you are in)
change directory
list the files in the current directory
list the variables in the workspace and their size
list the directories on the matlab path
Matlab has two shortcut keys "tab", which tries to autocomplete based on what is in the matlab path, and the "up arrow", which tries to autocomplete based on your matlab history. Matlab records your recent commands in the history so they can be recalled.

If you type 'w' and then hit "up arrow",
you should get the 'whos' command which you typed in earlier.

In a./b, a and b must be the same size - each element is divided by its neighbor.
The same goes for multiplication a*b is matrix division, if a is 4x3 and b is 3x1, then a*b is 4x1.
in a^b, a or b must be a scalar, the other must be a square matrix

from:to 1:9 = 1 to 9, 1:2:9 = 1 to 9 counting by odds
dont' print to screen 'a=1' will do the op and show result, 'a=1;' hides result
vector or matrix brackets [1 3 4] is row vector. [3 3; 1 1] is a square matrix
parentheses mean bracket and index or a function input.


Exercise: write an operation for pythagorean theorem, apply to scalar, vector and matrix
Variable types
>> a = 'text'
>> a = '1'
>> a = 1
Matlab has two variable types; double precision numbers and text.
Text is denoted by signle quotation only.
Text will be anything inside single quotes.
If something isnt inside single quotes, then its a number (double precision).
2) MATRIX BUILDING:
>> a = (1:2:5)'; n = 10;
>> diag(a);
>> eye(n)
>> ones(n); zeros(n);
>> repmat(a,1,n);
make column vector of [1 3 5]T
place vector a along the diagonal of a 3 x 3 matrix
make an identity matrix of 10 x 10
vector of ones, or zeros
concatenate the vector a, to make a 3 x 10 matrix
3) MATRICES, INDEXING, SUBSAMPLING
>> x= -2:10;
>> length(x); size(x); size(x,2);
>> x = -2:.5:10;
>> length(x); size(x); size(x,2);
a=magic(5);
a(2,3);
a(2,:);
a(:,3);
a(2:4,:);
a(:,3:5);
a(2:4,3:5);
a(1:2:5,:);

>> sum(a,2);
>> mean(a,2);
>> std(a,2);

make vector with spacing of 1 from -2 to 10
these are different ways to get the dimensions of 'x'
make vector with spacing of 0.5

make 5 x 5 magic matrix
one element
one row
one column



sub matrix (3 x 3)
subsample a row

basic stats





Exercise: Build a 10 x 10 matrix whose elements are 1 through 10 columnwise. Calculate the mean of the standard deviations of each column by nesting the functions, e.g. myfun1(myfun2(mymatrix)).
this is as far as we got.. (2)