Useful operators, commands, and concepts for this unit…
pi, ( ), [ ] :, whos, size(), rand(), mean(), std(), min(), max(), rem() (remainder after division), reshape(), repmat(), indexing, rows, columns
clear all before starting on these exercises. Keep some notes on what’s going on and try to understand each step and then move on to the next section
a = [3, pi, 10, 1; 2 7 4 1]
b = 20:3:30
c = 2
a .* c
a .* b
b .* c
d = a .* c
a, b, c, d, what about the following. Some of these are quite subtle, so make sure you understand:
% indexing into a
a(:,2)
a(1,4)
a(1)
a(2)
a(9)
a(4,4)
a(4,4) = 1.2
a
% ... and b
b(3,1)
b(1,3)
% spot the difference here:
e = rand(100,1)
e = rand(100,1);
% now that we have this:
mean(e)
… and now for matrices:
a
mean(a)
mean(a,1)
mean(a,2)
help mean
median(e)
std(e)
max(e)
min(e)
… and we can also keep track of where the min/max occurred:
[minValue minIndex] = min(e)
e(minIndex)
f = 1:100
rem(f,2) % remainder after division w/ 2
Not standard Matlab, but very useful helper functions from @justingardner
isodd(f)
iseven(f)
rem(f,3) + 1
rem(f+2,3) + 1
reshape():
size(f)
reshape(f,[10 10])
reshape(f,[2 50])
reshape(f,[2 40])
repmat():
repmat([1 2 3], 1, 5)
repmat([1 2 3], 5, 1)
More simple commands and some practice making vectors and matrices that contain specific things.