-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenSubset.m
More file actions
56 lines (51 loc) · 1.53 KB
/
genSubset.m
File metadata and controls
56 lines (51 loc) · 1.53 KB
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
function gensubset(types, max_per_type, tar, save_prefix)
p = 'D:\微云网盘\357812021\DropBox\Dropbox\Lab\毕设\dataset\';
subp = 'D:\微云网盘\357812021\DropBox\Dropbox\Lab\毕设\dataset\subset\';
df= '';
lf= '';
switch (tar)
case {'rtr',0},
df = 'train96';
dl = 'trainy';
case {'rte',1},
df = 'test96';
dl = 'testy';
case {'rftr',3},
df = 'trainfeatures';
dl = 'trainy';
case {'rfte',4},
df = 'testfeatures';
dl = 'testy';
case {'mftr',5},
df = 'mtrainFeatures';
dl = 'trainy';
case {'mfte',6},
df = 'mtestFeatures';
dl = 'testy';
end
load(strcat(p,df,'.mat'));
load(strcat(p,dl,'.mat'));
data = eval(df);
label= eval(dl);
[data,label] = parse(types,max_per_type,data,label);
save(sprintf('%s%s_data.mat',subp,save_prefix),'data');
save(sprintf('%s%s_label.mat',subp,save_prefix),'label');
end
function [subdata,sublabel] = parse(types,max_per_type,data,label)
[types] = sort(types);
subdata = [];
sublabel= [];
if max(types) > max(label) || min(types) < min(label)
return;
end
for i = 1:length(types)
I = find(label == types(i));
if length(I) > max_per_type
I = randsample(I,max_per_type);
end
n = length(I);
subdata(end+1:end+n,:) = data(I,:);
sublabel(end+1:end+n,:)= label(I,:);
end
return;
end