IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
get_feaidxs.m
Go to the documentation of this file.
1 %> @ingroup conversion
2 %> @file
3 %> @brief Returns indexes for manual feature selection
4 %>
5 %> Implements several ways of converting a list of features specificication
6 %> into the actual feature indexes
7 %>
8 %> <h3>Examples:</h3>
9 %> @code
10 %> % for v_type = 'x'
11 %> v = [1800, 1474; 1432, 1401; 1313, 1176; 1134, 900];
12 %>
13 %> % for type = 'i'
14 %> v = [1 86;97 105;128 163;174 235];
15 %> @endcode
16 %
17 %> @param x Feature x-axis, such as @ref irdata::fea_x
18 %> @param v Contains ranges or an index list (see v_type below) to include, 1 in each row.
19 %> @param v_type
20 %> @arg @c 'rx' if v is expressed in the same unit as data vars x
21 %> @arg @c 'ri' if v contains index ranges
22 %> @arg @c 'i' if v contains feature indexes
23 %> @param flag_complement If 1, will exclude the specified variables
24 %> @return indexes Vector of feature indexes
25 function indexes = get_feaidxs(x, v, v_type, flag_complement)
26 
27 if ~exist('v_type', 'var')
28  v_type = 'x';
29 end;
30 
31 if ~exist('flag_complement', 'var')
32  flag_complement = 0;
33 end;
34 
35 
36 
37 nf = length(x);
38 
39 if v_type == 'i'
40  indexes = v;
41 elseif v_type == 'x'
42  indexes = v_x2ind(v, x);
43 else
44  if v_type == 'rx'
45  ranges = v_x2ind(v, x);
46  elseif v_type == 'ri'
47  ranges = v;
48  end;
49 
50  indexes = [];
51  for i = 1:size(ranges, 1)
52  indexes = [indexes ranges(i, 1):ranges(i, 2)];
53  end;
54 end;
55 
56 if flag_complement
57  temp = 1:nf;
58  temp(indexes) = [];
59  indexes = temp;
60 end;
function v_x2ind(in v, in x)
Dataset class.
Definition: irdata.m:30
Analysis Session (AS) base class.
Definition: as.m:6