-
Notifications
You must be signed in to change notification settings - Fork 2
/
pca.m
55 lines (40 loc) · 925 Bytes
/
pca.m
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
saved_name = 'TRAIN';
s = load('TRAINTEST2D.mat',saved_name);
d = s.(saved_name);
data = d{1,4};
Z1 = data{1,1};
Z2 = data{1,2};
Z3 = data{1,3};
Z = cat(1,rotdim(Z1),rotdim(Z2),rotdim(Z3));
covZ = cov(Z);
[v,lambda] = eigs(covZ);
v1 = v(:,1);
zeroVect = zeros(17,1);
nZ1 = rotdim(Z1) * v1;
plot(nZ1,zeroVect,'r*','MarkerSize',8);
hold on;
nZ2 = rotdim(Z2) * v1;
plot(nZ2,zeroVect,'gs','MarkerSize',8);
hold on;
nZ3 = rotdim(Z3) * v1;
plot(nZ3,zeroVect,'b.','MarkerSize',8);
title('Training Data');
pause;
saved_name = 'TEST';
s = load('TRAINTEST2D.mat',saved_name);
d = s.(saved_name);
data = d{1,4};
Z1 = data{1,1};
Z2 = data{1,2};
Z3 = data{1,3};
zeroVect = zeros(16,1);
nZ1 = rotdim(Z1) * v1;
plot(nZ1,zeroVect,'r*','MarkerSize',8);
hold on;
nZ2 = rotdim(Z2) * v1;
plot(nZ2,zeroVect,'gs','MarkerSize',8);
hold on;
nZ3 = rotdim(Z3) * v1;
plot(nZ3,zeroVect,'b.','MarkerSize',8);
title('Testing Data');
pause;