IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
dataio_txt_libsvm.m
Go to the documentation of this file.
1 %> @brief Saver in LIBSVM format (loading currently not implemented)
2 %>
3 %> See also README file of LIBSVM containing data format specification.
5  properties
6  % The following properties affect the loading process and are unused at the moment
7 
8  %> 2-element vector specifying the wavenumber range.
9  %> This is necessary because this file format does not have this information.
10  %> However, the parameter is optional (the default data fea_x will be
11  %> [1, 2, 3, 4, ...])
12  range = [];
13 
14  %> (optional) Image height. If specified, will assign it the loaded dataset
15  height = [];
16  %> ='hor'. Whether the pixels are taken horizontally ('hor') or vertically ('ver') to form the image.
17  %> It was found that OPUS numbers the point in the image map left-right, bottom-up, hence 'hor'.
18  %> Same as irdata.direction (although irdata.direction has a different default).
19  direction = 'hor';
20  end;
21 
22  methods
23  function o = dataio_txt_libsvm()
24  o.flag_xaxis = 0;
25  o.flag_params = 1;
26  end;
27 
28 
29 
30  %> Loader
31  function data = load(o)
32  irerror('Loading not implemented at the moment');
33  end;
34 
35 
36 
37  %> Saver
38  function o = save(o, data)
39  h = fopen(o.filename, 'w');
40  if h < 1
41  irerror(sprintf('Could not create file ''%s''!', o.filename));
42  end;
43 
44  X = zeros(data.no, data.nf*2+1);
45  X(:, 1) = data.classes;
46 
47  fmt = '%d';
48  for j = 1:data.nf
49  fmt = [fmt, '\t%d:%f'];
50  X(:, j*2) = j;
51  X(:, j*2+1) = data.X(:, j);
52  end;
53  fmt = [fmt, '\n'];
54 
55  fprintf(h, fmt, X');
56  fclose(h);
57 
58  irverbose(sprintf('Just saved file "%s"', o.filename), 2);
59  end;
60  end
61 end
function irverbose(in s, in level)
function irerror(in s)
Dataset class.
Definition: irdata.m:30
Dataset loader/saver common class.
Definition: dataio.m:2
Analysis Session (AS) base class.
Definition: as.m:6
Saver in LIBSVM format (loading currently not implemented)