1.加減乘除冪
octave:5> 6+6
ans =? 12
octave:6> 1/2
ans =? 0.50000
octave:7> 5*8
ans =? 40
octave:8> 2^3
ans =? 8
2.等于/不等/注釋/與/或/異或
octave:9> 1==2 %false
ans = 0
octave:10> 1~=2 %true
ans = 1
octave:11> 1&&0 % and
ans = 0
octave:12> 1||0 % or
ans = 1
octave:13> xor(1,0)
ans = 1
3.改變命令符號
octave:14> PS1('>>');
4.變量
>>a=3
a =? 3
>>a=3;
>>a
a =? 3
>>a=3;% semicolon supressing output
>>b='hi';
>>b
b = hi
>>a=pi;
>>a
a =? 3.1416
>>disp(a);
?3.1416
>>disp(sprintf('2 decimals:%0.2f',a))
2 decimals:3.14
>>disp(sprintf('2 decimals:%0.4f',a))
2 decimals:3.1416
>>format long
>>a
a =? 3.141592653589793
>>format short
>>a
a =? 3.1416
5.矩陣
>>A=[1 2;3 4;5 6]
A =
?? 1? 2
?? 3? 4
?? 5? 6
>>A=[1 2;
> 3 4凶赁;
> 5 6]
A =
?? 1? 2
?? 3? 4
?? 5? 6
>>V=[1;
> 2;
> 3]
V =
?? 1
?? 2
?? 3
>>V=1:0.1:2 ? ? ? %行向量
V =
?Columns 1 through 8:
? ? 1.0000? ? 1.1000? ? 1.2000? ? 1.3000? ? 1.4000? ? 1.5000? ? 1.6000? ? 1.7000
?Columns 9 through 11:
? ? 1.8000? ? 1.9000? ? 2.0000
>>V=1:6
V =
?? 1? 2? 3? 4? 5? 6
>>ones(2,3)
ans =
?? 1? 1? 1
?? 1? 1? 1
>>2*ones(2,3)
ans =
?? 2? 2? 2
?? 2? 2? 2
>>w=ones(1,3)
w =
?? 1? 1? 1
>>w=zeros(1,3)
w =
?? 0? 0? 0
>>w=rand(1,3)
w =
?? 0.20737? 0.49201? 0.55104
>>w=rand(3,3)
w =
?? 0.38282? 0.24781? 0.50397
?? 0.32993? 0.10644? 0.54189
?? 0.33615? 0.13661? 0.26884
>>w=randn(1,3) ??
w =
? -0.13863? 0.70373? 0.65798
>>h=-6+sqrt(10)*(randn(1,10000));
>>hist(h)
>>eye(4)
ans =
Diagonal Matrix
?? 1? 0? 0? 0
?? 0? 1? 0? 0
?? 0? 0? 1? 0
?? 0? 0? 0? 1