-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathconvert_labels.m
More file actions
30 lines (26 loc) · 807 Bytes
/
convert_labels.m
File metadata and controls
30 lines (26 loc) · 807 Bytes
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
function [y ordering] = convert_labels(x,C)
% [y, ordering] = convert_labels(x,C)
% Convert from short form labelling to long form labelling and so forth
% Output:
% y -- The converted labels
% ordering -- Used when converting from long to short form. Returns
% the final ordering so that the dataset can be
% rearranged if need be.
d = length(x);
% Check which conversion mode we're in
if d ~= C
LONG_TO_SHORT = 1;
else
LONG_TO_SHORT = 0;
end
y = [];
if LONG_TO_SHORT
% Convert from long form labelling to short form labelling
[sorted_labels ordering] = sort(x,'ascend');
y = hist(x,unique(sorted_labels));
else
% Convert from short form labelling to long form labelling
for i=1:d
y = [y i*ones(1,x(i))];
end
end