Octave Notes
Octave Notes from Coursera online Machine Learning Course
Basic Operation
~=: not equal2^6&&and||or%commentPS1('>> ')change prompt;not show resultsa=3a='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:2orv=1:6ones,zeros,rand,randnfor random normal,eyesqrthist(w, bins=50)helpA(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
pwdcdlsload ***.dat,load('***.dat')who,whos, =lssave hello.txt v
Data/Matrix
A*CA .* CandA .^ 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 onxlabel('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 graysurf: 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