-
Notifications
You must be signed in to change notification settings - Fork 2
/
Tra_distance_matrix_using_dtw_index_randomK.m
45 lines (30 loc) · 1.32 KB
/
Tra_distance_matrix_using_dtw_index_randomK.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
function [distance_Mat,index_Mat] = Tra_distance_matrix_using_dtw_index_randomK(latLong_using_prototypes_index, SP, randnum, num)
[index_of_trajectory, pointer_start] = unique(latLong_using_prototypes_index(:,1),'stable');
numberOfTrajectories = length(index_of_trajectory);
distance = zeros(1,numberOfTrajectories);
distance_Mat = zeros(num,numberOfTrajectories-1);
index_Mat = zeros(num,numberOfTrajectories-1);
SPdistMat = dist(SP,SP');
for indxxx = 1:num
i = randnum(indxxx);
if i ~= numberOfTrajectories
a = latLong_using_prototypes_index(pointer_start(i) : pointer_start(i+1)-1,2);
else
a = latLong_using_prototypes_index(pointer_start(i) : end,2);
end
for j = 1: numberOfTrajectories
if j ~= numberOfTrajectories
b = latLong_using_prototypes_index(pointer_start(j) : pointer_start(j+1)-1,2);
else
b = latLong_using_prototypes_index(pointer_start(j) : end,2);
end
distance(j) = Tra_index_dtw(a,b,SPdistMat);
distance(j) = min(Tra_index_dtw(a,b(end:-1:1),SPdistMat), distance(j));
end
[distance, index] = sort(distance); % without 'descend'!
distance(index == i) = [];
index(index == i) = [];
distance_Mat(indxxx,:) = distance;
index_Mat(indxxx,:) =index;
end
end