1.Basic Operations
5+6
3-2
5*8
1/2
2^6
1 == 2 %false ans = 0
1 ~= 2 %true ans = 1
1 && 0 %AND ans = 0
1 || 0 %OR ans = 1
xor(1,0) %ans = 1
PS1('>> '); %change the command prompt info
a = 3 %show a = 3 in screen
a = 3 %not show a = 3 in screen
b = 'hi'
c = (3>=1)
a = pi; %a = 3.1416
disp(sprintf('2 decimals: %0.2f',a)) %2 decimals: 3.14
disp(sprintf('6 decimals: %0.6f',a)) %2 decimals: 3.141593
format long %a = 3.14159265358979
format short %a = 3.1416 2. Matrices and Vectors
A = [1 2; 3 4; 5 6]
v = [ 1 2 3]
v = [1; 2; 3]
v = 1:0.1:2 %1.0 1.1 1.2 ... 2.0
v = 1:6
v = ones(2,3)
c = 2*ones(2,3)
w = ones(1,3)
w = zeros(1,3)
w = rand(1,3)
w = rand(3,3)
w = randn(1,3) %Gossian distribution
w = -6 + sqrt(10)*(randn(1,10000))
hist(w) %draw a histogram
hist(w,50)
I = eye(4)
help eye
help rand
help help 3.Moving data around
A = [1 2; 3 4; 5 6]
size(A) %ans = 3 2
size(A,1) %ans = 3
size(A,2) %ans = 2
A(3,2) %ans = 6
A(2,:) %the second row, ':' means every elements along that row/column
A(:,2) %the second column
A([1 3],:) %the first and the third row
A(:,2) = [10; 11; 12]
A = [A, [100; 101; 102]] %append another column vector to right
A(:) %put all elements of A into a single vector
A = [1 2; 3 4; 5 6]
B = [11 12; 13 14; 15 16]
C = [A B] %3 * 4
C = [A; B] %6 * 2 v = [1 2 3 4]
length(v) %ans = 4
length(A) %ans = 3
length([1;2;3;4;5]) %ans = 5 pwd %current path
cd 'path...'
ls load featuresX.dat
load priceY.dat
load('featuresX.dat')
load('priceY.dat') who %show the variables in current scope
whos %show the variables detail in current scope
size(featuresX) %ans = 47 2 v = priceY(1:10) save hello.mat v; %save v into a file named "hello.mat"(BINARY)
save hello.txt v; %txt format can be understood by human(ASCII)
clear featuresX %delete featuresX from current scope
clear %delete all variables in current scope 4.Computing on data
A = [1 2; 3 4; 5 6]
B = [11 12; 13 14; 15 16]
C = [1 1; 2 2]
A*C
A.*B %'.' element operation
A.^2
v = [1; 2; 3]
1./v
log(v)
exp(v)
abs(v)
-v %-1*v
v + ones(length(v),1) % v + 1, v + ones(3,1)
A' %transpose a = [1 15 2 0.5]
val = max(a) %val = 15
[val, ind] = max(a) %val=15 ind(ex)=2
max(A) %ans = 5 6
a < 3 %element wise comparison: ans = 1 0 1 1
find(a<3) %ans = 1 3 4
A = magic(3)
[r, c] = find(A>=7) % r = 1; 3; 2 c = 1; 2; 3 ==>A(1,1) A(3,2) A(2,3) are greater than 7
help find
sum(a)
prod(a)
floor(a)
ceil(a)
max(rand(3),rand(3))
max(A,[],1) %the maximum element in each column
max(A,[],2) %the maximum element in each row
max(A) %ans = 8 9 7
max(max(A)) %ans = 9
max(A(:)) %ans = 9
A = magic(9)
sum(A,1) %sum up each column
sum(A,2) %sum up each row
sum(sum(A.*eye(9))) %sum up the main diagonal
sum(sum(A.*flipud(eye(9)))) %sum up the other diagonal
pinv(A) %pseudo inverse 5. Plotting Data
t = [0:0.01:0.98]
y1 = sin(2*pi*4*t)
plot(t,y1);%sin function
y2 = cos(2*pi*4*t)
hold on; %put figures in one window
plot(t,y2,'r') %change the color of cos to red
xlabel('time')
ylabel('value')
legend('sin','cos')
title('my plot')
cd '/home/zhanghe';
print -dpng 'myPlot.png'
close
figure(1);plot(t,y1);
figure(2);plot(t,y2);
subplot(1,2,1) %%divides plot into 1*2 grid access first element
plot(t,y1);
subplot(1,2,2) %%divides plot into 1*2 grid access second element
plot(t,y2);
axis([0.5 1 -1 1])
clf;
A = magic(5)
imagesc(A)
imagesc(A),colorbar,colormap 6. Control statements
v = zeros(10,1)
for i=1:10,
v(i) = 2^i;
end;
indices = 1:10;
for i=indices,
disp(i);
end;
i = 1;
while i<=5,
v(i) = 100;
i = i+1;
end;
while true,
v(i) = 999;
i = i+1;
if i==6,
break;
end;
end;
v(1) = 2;
if v(1) == 1,
disp('One');
elseif v(1) == 2,
disp('Two');
else
disp('Else');
end; %Octave search path (advanced/optional)
addpath('/home/zhanghe/ml/ex1') %Example of CostFunction
predictions = X*theta;
sqrErrors = (predictions-y).^2;
J = 1/(2*m) * sum(sqrErrors); 7.Vectorization
% Hypothesis Function
% Unvectorized implementation
prediction = 0.0;
for j = 1:n+1,
prediction = prediction + theta(j) * x(j)
end;
% Vectorized implementation
prediction = theta' * x % Gradient descent(Simultaneous updates)
% Vectorized implementation
delta = 1/m*((hypothesis-y)*x)
theta = theta - alpha*delta

CheeseZH: Octave basic commands的更多相关文章

  1. Network Basic Commands Summary

    Network Basic Commands Summary set or modify hostname a)     temporary ways hostname NEW_HOSTNAME, b ...

  2. Postgres Basic Commands for Beginners

    Just sharing what I have learned about postgres recently. Here is a part of basic commands you may n ...

  3. Linux--Introduction and Basic commands(Part one)

    Welcome to Linux world! Introduction and Basic commands--Part one J.C 2018.3.11 Chapter 1 What Is Li ...

  4. linux basic commands

    1. man - an interface to the on-line reference manuals $man man 2. apt - advanced package tool SEE A ...

  5. kafka basic commands

    kafka-server-start.sh config/server.properties & kafka-server-stop.sh kafka-topics.sh    --creat ...

  6. Kali Basic Configuration

    1:Kali Version root@kali-node01:~# cat /etc/os-release PRETTY_NAME="Kali GNU/Linux Rolling" ...

  7. 13 Basic Cat Command Examples in Linux

    FROM: http://www.tecmint.com/13-basic-cat-command-examples-in-linux/ The cat (short for “concatenate ...

  8. [C2P1] Andrew Ng - Machine Learning

    About this Course Machine learning is the science of getting computers to act without being explicit ...

  9. 【转】Redis入门

    Redis是一个开源,先进的key-value存储,并用于构建高性能,可扩展的Web应用程序的完美解决方案. Redis从它的许多竞争继承来的三个主要特点: Redis数据库完全在内存中,使用磁盘仅用 ...

随机推荐

  1. Linux性能监控分析命令(三)—iostat命令介绍

    性能监控分析的命令包括如下: 1.vmstat 2.sar 3.iostat 4.top 5.free 6.uptime 7.netstat 8.ps 9.strace 10.lsof 命令介绍: i ...

  2. 通过Roslyn构建自己的C#脚本(更新版)

    之前写过文章介绍过如何通过Roslyn构建自己的C#脚本,但那篇文章是参考自Roslyn CTP版的,记得本来想等到Roslyn正式版出来重新更新一下文档的,不过记得后来Roslyn是跳票了的,Scr ...

  3. 使用LM2576制作数控电源

    http://www.daxia.com/bibis/moredata30_1207792_29862.shtml 图中DA和PWM任选其一, 当DA或PWM输出为0~1.25V时,输出在12.5V~ ...

  4. Codeforces Round #309 (Div. 2) C. Kyoya and Colored Balls

    Kyoya Ootori has a bag with n colored balls that are colored with k different colors. The colors are ...

  5. BMP文件格式实例分析

    1. 以下为一个RGB565-16位BMP位图实际的部分数据: 00000000h: 42 4D 46 58 02 00 00 00 00 00 46 00 00 00 28 00 ; BMFX... ...

  6. MVC自定义编辑视图,DateTime类型属性显示jQuery ui的datapicker

    实现的效果为:在编辑视图中,对DateTime类型的属性,显示jQuery UI的datepicker.效果如下: Student.cs public class Student    {       ...

  7. extjs表单验证

    extjs表单验证 //放在onReady的function(){}中 Ext.QuickTips.init(); //为组件提供提示信息功能,form的主要提示信息就是客户端验证的错误信息. Ext ...

  8. [翻译] Working with NSURLSession: AFNetworking 2.0

    Working with NSURLSession: AFNetworking 2.0   简单翻译,有很多错误,看官无法理解处请英文原文对照. http://code.tutsplus.com/tu ...

  9. C# 模拟网站登陆

    实现此功能首先需要借助一些抓包工具,对相应的网站登陆过程进行分析,此过程根据网站的不同,可能复杂,也可能很简单.常用的抓包工具FF下FireBug和IE下的HttpWatch.这两个工具很强大,以此工 ...

  10. my.cnf 配置文件参数解释

    my.cnf 配置文件参数解释: #*** client options 相关选项 ***# #以下选项会被MySQL客户端应用读取.注意只有MySQL附带的客户端应用程序保证可以读取这段内容.如果你 ...