IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
peak_closest.m
Go to the documentation of this file.
1 %>@ingroup maths
2 %>@file
3 %> @brief Returns index of peak closest to @c a.
4 %>
5 %> @sa db_peaks.m
6 %
7 %> @param db Data structure obtained from db_peaks.m
8 %> @param a can be either the index of a wavenumber or the wavenumber itself, because it is easy to distinguish one from the
9 %> other
10 %> @return result is an index of an element in db, such as db.names(result), db.centres(result) of db.indexes(result)
11 function result = peak_closest(db, a)
12 
13 
14 flag_wn = a > 250;
15 
16 if flag_wn
17  v = db.centres;
18 else
19  v = db.indexes(end:-1:1);
20 end;
21 
22 result = 0;
23 for i = 1:length(v)
24  if v(i) < a
25  if i == 1
26  result = i;
27  elseif (a-v(i)) < (v(i-1)-a)
28  result = i;
29  else
30  result = i-1;
31  end;
32  break;
33  end;
34 end;
35 if result == 0
36  result = length(v);
37 end;
38 
39 if ~flag_wn
40  result = length(v)+1-result;
41 end;
42 
function peak_closest(in db, in a)
Analysis Session (AS) base class.
Definition: as.m:6