octave

octave

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#保存文件
save hello.mat v
save hello.txt v -ascii % save as text (ASCII)
# 切片
A=[1 2; 3 4 ;5 6]
A(3,2)
A(2,:) % ":" means every element along that row/column
A(:,2)
A([1 3],:)# 第1和3列
A(:,2)=[10;11;12]
A = [A,[100; 101; 102]]; % append another column vector to right
A = [A,[COLUMN VECTOR]];

size(A)
A(;) % put all element of A into a single vector

## form matrix
A=[1 2; 3 4 ;5 6]
B=[11 12; 13 14; 15 16]
C=[A B] % right and left
C=[A;B] % top and bottom


############## moving data around
A=[1 2; 3 4 ;5 6]

size(A)
size(A,1)
size(A,2)
length(v)
length(A)
length([1;2;3;4;5])



## directory
pwd
cd directory
ls

load featuresX.data
load('featuresX.data')


############ 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 % 每个数据点分别操作。
A.^2
A./V
1 ./A

log(v)
exp(v)
abs(v)
-v % -1 *v
v+ones(length(v),1)
A'
[val,ind]=max(a)
a<3
find(a<3)
A=magic(3) ## generate 3*3 matirx
[r c]=find(A>7) # return column and row

sum(a)
prob(a)
floor(a)
ceil(a)
rand(3) # 产生一个3*3的随机矩阵
max(rand(3),rand(3))
max(A,[],1)
max(A,[],2)


A(:)
max(max(A))

A=magic(9)
sum(A,1)
sum(A,2)

A.*eye(9)
sum(A.*eye(9))
sum(sum(A.*eye(9)))

sum(sum(A.*flipud(eye(9)))) %flipud: 反向对角线



### 画图
t=[0:0.01:0.98];
y1=sin(2*pi*4*t);
y2=cos(2*pi*4*t);
plot(t,y1);
hold on;
plot(t,y2,'r');
xlabel("time")
ylabel("value")
title("myplot")
legend('sin','cos')