Skip to content

Instantly share code, notes, and snippets.

@rschildmeijer
Created September 22, 2015 19:56
Show Gist options
  • Save rschildmeijer/0f98a4840b49ea13d317 to your computer and use it in GitHub Desktop.
Save rschildmeijer/0f98a4840b49ea13d317 to your computer and use it in GitHub Desktop.
machine learning
MATRIX / MATLAB
I = v < 0.05 # I contains 1 or 0 depending on logical criteria
v(I) = 0 # element vise assign 0 where I is 1 (True)
A .* B # element wise multiplication
1 . / v # element wise division (1 / element)
v + 1 # element wise
a < 3 # element wise comparision
log(v), exp(v), abs(v) # element wise
sum(a), prod(a), floor(a)
rand(3)
[val, index] = max(a) # column wise maximum
find(a < 3)
magic(n)
[row, column] = find(A >= 7) # row / col contains index pairs that match the predicate
max(A, [], 1) # per column wise max
max(A, [], 2) # per row wise max
max(max(A)) == max(A(:)) # max value in A
sum(A, 1) # column wise sum
sum(A, 2) # row wise sum
flipud (A) # flip the matrix :)
pinv(A) # pseudo inverse of A
PLOT
hold on; # plot in same figure
close; # close figure
xlabel(‘x’)
ylabel(‘y’)
legend(‘abc’)
title(‘zxy’)
print -dpng ‘plot.png’
figure(1); plot(x, y)
subplot(1,2,1) # divides plot a 1x2 grid, access first element
axis([0.5 1 -1 1]) # set x and y axis
clf # clear figure
imagesc(A) the # color stuff
imagesc(A), colorbar, colormap gray
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment