1 %> @brief Basic TXT loader/saver
3 %> Description of the
"basic" file type (Figure 1):
5 %> <li>Table of data with no header and last column containing the class index.</li>
6 %> <li>Delimiters such
as ';',
' ', or
'\t' (Tab) are supported.</li>
9 %> Because class labels and x-axis are not stored in the file,
11 %> <li>Class labels are made up
as "Class 0",
"Class 1" etc</li>
12 %> <li>Unless the x-axis range is passed to load(), the default value [1801.47, 898.81] (Bruker Tensor27-aquired spectra, then cut to
13 %> 1800-900 region in OPUS)</li>
15 %> @image html dataformat_basic.png
16 %> <center>Figure 1 - basic TXT file type</center>
20 %> 2-element vector specifying the wavenumber range.
21 %> This is necessary because this file format does not have this information.
22 %> However, the parameter is optional (the default data fea_x will be
26 %> (optional) Image height. If specified, will assign it the loaded dataset
28 %> =
'hor'. Whether the pixels are taken horizontally (
'hor') or vertically (
'ver') to form the image.
29 %> It was found that OPUS numbers the point in the image map left-right, bottom-up, hence 'hor'.
30 %> Same
as irdata.direction (although
irdata.direction has a different default).
43 function data = load(o)
49 data.fea_x = 1:no_cols-1;
51 data.fea_x = linspace(o.range(1), o.range(2), no_cols-1);
57 mask_data = [repmat('%f', 1, no_cols-1) '%q'];
59 % Opens for the second time in order to actually read the file
60 fid = fopen(o.filename);
62 c_data = textscan(fid, mask_data, 'Delimiter', delimiter);
66 data.X = cell2mat(c_data(1:end-1));
69 clalpha = c_data{end};
71 clalpha = cellfun(@num2str, num2cell(clalpha), 'UniformOutput', 0);
75 no_obs = size(data.X, 1);
76 data.classes(no_obs, 1) = -1; %
pre-allocates
78 data.classes(i) = find(strcmp(data.classlabels, clalpha{i}))-1;
82 data.assert_not_nan();
83 data.filename = o.filename;
84 data.filetype =
'txt';
86 data.height = o.height;
87 data.direction = o.direction;
98 function o = save(o, data)
100 h = fopen(o.filename, 'w');
102 irerror(sprintf('Could not create file ''%s''!', o.filename));
108 fwrite(h, [sprintf('%g\t', data.X(i, :)) labels{i} sprintf(
'\n')]);
113 irverbose(sprintf(
'Just saved file "%s"', o.filename), 2);
function irverbose(in s, in level)
Pre-processing block base class.
function classes2labels(in classes, in labels)
Dataset loader/saver common class.
Analysis Session (AS) base class.
function unique_appear(in classlabels)
function get_no_cols_deli(in filename)