Octave Notes
Octave Notes from Coursera online Machine Learning Course
Basic Operation
~=
: not equal2^6
&&
and||
or%
commentPS1('>> ')
change prompt;
not show resultsa=3
a='hi'
- pi
disp(a)
sprintf('fsdf %0.2f', a)
, string printformat long/short
Math
std
sqrt
log
exp
sin, cos
Matrix/Vector
A=[1 2;3 4;5 6]
v=1:0.1:2
orv=1:6
ones
,zeros
,rand
,randn
for random normal,eye
sqrt
hist(w, bins=50)
help
A(2,:)
A([1 3],:)
: 1st, 3rd rowA=[A, [1;2;3]]
: append columnsize(A)
andsize(A,1)
length(v)
C=[A B]
C=[A;B]
File/Imput/Save
pwd
cd
ls
load ***.dat
,load('***.dat')
who
,whos
, =lssave hello.txt v
Data/Matrix
A*C
A .* C
andA .^ 2
; elementwise- abs, log, exp
- transpose
A'
- max(a), max(A,[],1), column max, max(A,[],2), row max
[val, ind] = max(a)
find(a < 3)
magic(3)
[r,c]=find(A>7)
sum, prod, floor, ceil, sum(A,1), pinv, inv
Plot
plot(x,y,'rx')
: r is color, x marker, ‘-‘ for lines, ‘+’, ‘o’hold on
xlabel('time')
legend('sin', 'cos')
title('title')
print -dpng 'xxx.png'
: save to pngfigure(1)
subplot(1,2,1)
axis([0.5 1 -1 1])
imagesc(A), colorbar, colarmap gray
surf
: 3-dcontour
: contour
Clear
clear
clc
close all
Loop
for i = 1:10,
statement;
end;
indices=1:10;
for i = indices,
...
while i<=5,
...
break;
end;
if i<=5,
...
elseif ...,
else
...
end;
2:end
Function
need to name myfunction.m, and put in the pwd
function [y1, y2]=myfcn(x)
y1=...
addpath('C:fff')
fmincg
submit homework
change to homework directory, after you finish, just type
submit()
Emacs
(autoload 'octave-mode "octave-mod" nil t)
(setq auto-mode-alist
(cons '("\\.m$" . octave-mode) auto-mode-alist))
(add-hook 'octave-mode-hook
(lambda ()
(abbrev-mode 1)
(auto-fill-mode 1)
(if (eq window-system 'x)
(font-lock-mode 1))))
C-c Tab l : exec line
Published
17 September 2012