matlab & ocatve
- index 从1开始
- length 长度
io
- data = open(“data.file”);
cmd
- clear ; close all; clc
- clc:清除命令窗口的内容,对工作环境中的全部变量无任何影响
- close:关闭当前的Figure窗口
- close all:关闭所有的Figure窗口
- clear:清除工作空间的所有变量
- clear all:清除工作空间的所有变量,函数,和MEX文
- fprintf(‘hello world \n’)
- % comment
convension
- X (m,n + 1)
- y (m,1)
- theta (n+1,1)
matrix Utility
- 列用;分割 行用,分割
- a = [1;2;3]
- X = data(:,1) 取第一列
- X = data(:,[1,2]) 取1,2 列
- 获取非0序号 Find
- pos = find(y==1)
- size
- [m , n] = size(X)
- X = [ones(m, 1) X];
- 全0矩阵 zeros(x,y)
- 全1矩阵 ones(x,y)
- 单位矩阵 I = eye(n) Identity Martix
- 矩阵赋值:assignment
- X(i,y) = n
gen
- linspace (BASE, LIMIT, N)
1
2
3linspace(1,4,5)
ans =
1.0000 1.7500 2.5000 3.2500 4.0000 - logspace(-2, 3, 5)
1
2
3logspace(-2, 3, 5)
ans =
1.0000e-02 1.7783e-01 3.1623e+00 5.6234e+01 1.0000e+03
logic
- for
1
2
3for i = 1:n
do_something...
end
plot
- figure; % open a new figure window
- plot
- 3D:surf(X,Y,V)
- 等高线: contour(X,Y,V,logspace(-2,3,20))
minimizers
- options = optimset(‘GradObj’, ‘on’, ‘MaxIter’, 400);
- [theta, cost] = fminunc(@(t)(costFunction(t, X, y)), initial_theta, options);