Octave Matrices
Addition
Make two matrices addition.
>> A = [1, 2, 3; 4, 5, 6]
1 2 3
4 5 6
>> B = [11, 22, 33; 44, 55, 66]
11 22 33
44 55 66
>> A + B
12 24 36
48 60 72
Range
Define vector range, default step is 1.
>> v = 1:6
1 2 3 4 5 6
>> v = 1:0.2:2
1.0000 1.2000 1.4000 1.6000 1.8000 2.0000
Identity
Create an identity matrix (1 on diagonal).
>> eye(4)
Diagonal Matrix
1 0 0 0
0 1 0 0
0 0 1 0
0 0 0 1
Wise operations
Matrix wise operations,
>> A
1 2
3 4
5 6
>> B
11 12
13 14
15 16
>> A .* B
11 24
39 56
75 96
>> v = [1; 2; 3]
1
2
3
>> 1 ./ v
1.00000
0.50000
0.33333
Column wise maximum.
>> A = magic(3)
8 1 6
3 5 7
4 9 2
>> max (A,[],1) % column wise maximum
8 9 7
>> max (A,[],2) % row wise maximum
8
7
9
>> max(A(:)) % vector
9
Find operatiions
Vector maximum value.
>> a = [1 15 2 0.5]
1 15 2 0.5
>> val = max(a)
15
>> [val, ind] = max(a)
val = 15
ind = 2
Find indexes.
>> A = magic(3)
8 1 6
3 5 7
4 9 2
>> [r,c] = find (A >= 7)
r =
1
3
2
c =
1
2
3
>> A(2,3)
7
Last update: 249 days ago