-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsetDataset_classIDs_ByAttribFile.m
executable file
·77 lines (67 loc) · 2.04 KB
/
setDataset_classIDs_ByAttribFile.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
77
% Set the class-IDs of a dataset by a given attribute-file.
%
% Author: Maurice Hollmann
% Date : 08/10
%
% Description:
%
% [dataset] = setDataset_classIDs_ByAttribFile(dataset, attribFile)
%
% This methods sets the classIDs of the given dataset.
% The given attributes file must be in ASCII-format.
% An attributse file has the content (classID chunk):
%
% 0 0
% 0 1
% 0 1
% 1 0
% 1 2
% 1 2
% . .
% . .
%
% For regression the classIDs may also be doubles:
%
% 0.23 0
% 0.1 1
% 0.98 1
% 1.23 0
% 3.2456 2
% 0.2 2
% . .
% . .
%
%
% Parameters:
% dataset - the datset to set the classIDs for
% attribFile - ASCII-formatted file holding chunk and classID information
%
% Returns:
% dataset - the datset with included classIDs
%
% Comments:
%
function [dataset] = setDataset_classIDs_ByAttribFile(dataset, attribFile)
if(~exist('dataset', 'var') || ~exist('attribFile', 'var'))
disp('Usage of setDataset_classIDs_ByAttribFile : [dataset] = setDataset_classIDs_ByAttribFile(dataset, attribFile [ASCII-formatted file])');
return;
end
if(~exist(attribFile, 'file'))
error(['setDataset_classIDs_ByAttribFile: Attributes file: ', attribFile, ' does not exist!']);
end
fid = fopen(attribFile);
attribs = textscan(fid, '%s', 'delimiter', '\n');
fclose(fid);
dataset.classIDs = zeros(1, size(attribs{1},1));
%loop over lines
for i=1:size(attribs{1},1)
attribLine = str2num(char(attribs{1}(i)));
if(numel(attribLine)==0)
error('ERROR: It seems as there are empty lines in your attribute file, please remove these first!');
end
dataset.classIDs(i) = attribLine(1);
end
if(~checkDataset(dataset))
disp('WARNING: setDataset_classIDs_ByAttribFile: In the current state the dataset is not suitable for further processing, please see messages before!');
end
end