Skip to content

Instantly share code, notes, and snippets.

@junichiro
Last active January 10, 2017 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save junichiro/a895b85ae4dc9a2e25f105a58cc120d3 to your computer and use it in GitHub Desktop.
Save junichiro/a895b85ae4dc9a2e25f105a58cc120d3 to your computer and use it in GitHub Desktop.
機械学習を1ヵ月で実践レベルにする #3 (Octave 編) ref: http://qiita.com/junichiro/items/33954f08411e33d33506
% octave-cli
>> ls
>> pwd
>> cd hoge
>> a = 1
a = 1
>> a = [1 2]
a =
1 2
>> a = [1;2;3]
a =
1
2
3
>> a = [1 2; 3 4]
a =
1 2
3 4
>> a = pi;
>> a
a = 3.1416
>> v = 1:0.3:2 % 初期値:ステップ数:終値
v =
1.0000 1.3000 1.6000 1.9000
>> v = 1:6 % 初期値:(ステップ数1を省略):終値
v =
1 2 3 4 5 6
>> ones(2,3)
ans =
1 1 1
1 1 1
>> zeros(3,2)
ans =
0 0
0 0
0 0
>> 2*ones(2,3)
ans =
2 2 2
2 2 2
>> w = rand(2,3)
w =
0.958006 0.225452 0.932911
0.039494 0.743074 0.607472
>> m = magic(3) % nxn の魔法陣を作る
m =
8 1 6
3 5 7
4 9 2
>> eye(5)
ans =
Diagonal Matrix
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
>> A = [1 2; 3 4; 5 6]
A =
1 2
3 4
5 6
>> size(A)
ans =
3 2
>> size(A, 1)
ans = 3
>> size(A, 2)
ans = 2
>> v = [1 2 3 4]
v =
1 2 3 4
>> length(v)
ans = 4
>> A(1,:)
ans =
1 2
>> A(2,:)
ans =
3 4
>> A(:,1)
ans =
1
3
5
>> A(:,2)
ans =
2
4
6
>> A(:)
ans =
1
3
5
2
4
6
>> A(1:1)
ans = 1
>> A(1:2)
ans =
1 3
>> A(1:3)
ans =
1 3 5
>> A([1,3], :)
ans =
1 2
5 6
>> A(:,2) = [10;11;12]
A =
1 10
3 11
5 12
>> A = [A, [100; 101; 102]]
A =
1 10 100
3 11 101
5 12 102
>> A' % 転置
ans =
1 3 5
10 11 12
100 101 102
>> who % 定義されている変数の一覧
Variables in the current scope:
A a ans m v w
>> whos % 定義されている変数の一覧とそのサイズなど
Variables in the current scope:
Attr Name Size Bytes Class
==== ==== ==== ===== =====
A 3x2 48 double
a 1x1 8 double
ans 3x1 24 double
m 3x3 72 double
v 1x4 32 double
w 2x3 48 double
Total is 29 elements using 232 bytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment