-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdataconverter.m
executable file
·76 lines (73 loc) · 2.04 KB
/
dataconverter.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
function [ D, G ] = dataconverter (strfile, detect, indicator)
% indicator - is a cell to indicat the meaning of number in detect.
% detect - a cell to store the time of events.
% strfile - name of the corresponding data file.
%
% Example:
% file = 'ls_gt_ls';
% result = { gt , ls , lt };
% events = {'gt','ls','lt'};
% [D, G] = dataconverter (file, result, events)
%
D = []; G = [];
if nargin < 3
disp('Error: Not enough arguments!')
return
end
if length(indicator) ~= length(detect)
disp('Error: The first two arguments must have the same dimension!')
return
end
if isempty(detect)
disp('Error: Detected result cannot be empty!')
return
end
for i=1:length(detect)
if min(size(detect{i})) > 1
disp('Error: Members in detected resulit must be vectors !')
return
end
detect{i} = sort(detect{i});
end
d = 10; g = 5; % length of data set for detection and groudtruth
[ times, events ] = parsename( strfile );
D = -1*ones(length(events),d); % store detection
G = -1*ones(length(events),g); % store groundtruth
for i=1:length(detect)
ind = find(ismember(events,indicator{i}));
for j=1:length(detect{i})
if isempty(detect{ind})
break
end
D(i,j) = detect{i}(j);
end
for j=1:length(times{i})
if isempty(times{ind})
break
end
G(i,j) = times{ind}(j);
end
end
end
function [ times, events ] = parsename( strfile )
ind = strfind(strfile,'.xlsx');
strfile = strfile(1:ind(1)-1);
events = {'gt','lt','ls'};
times = cell(length(events),1);
for i=1:length(times)
index = strfind(strfile,events{i});
if isempty(index)
continue
end
for j=1:length(index)
temp = strfile(index(j):end);
id = strfind(temp, '_');
if length(id) == 1
times{i} = [times{i} ; str2double(temp(id+1:end))];
else
times{i} = [times{i} ; str2double(temp(id(1)+1:id(2)-1))];
end
end
times{i} = sort(times{i});
end
end