IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
ask_hierarchy.m
Go to the documentation of this file.
1 %> @ingroup guigroup
2 %> @file
3 %> @brief Asks uses to type in dataset class levels (for varying purposes).
4 %> @image html Screenshot-ask_hierarchy.png
5 
6 %> @param data Dataset (@ref irdata object)
7 %> @param title Dialog title
8 %> @param flag_all Whether to allow "all" (empty vector) option.
9 %> @return A structure containing the following fields: @c params; @c flag_ok
10 function result = ask_hierarchy(data, title, flag_all)
11 result.flag_ok = 0;
12 
13 cc = classlabels2cell(data.classlabels);
14 
15 s_all = '';
16 if flag_all
17  s_all = ' ([] = all)';
18 end;
19 no_levels = size(cc, 2)-4;
20 s_plural = '';
21 if no_levels ~= 1
22  s_plural = 's';
23 end;
24 
25 while 1
26  p = inputdlg(sprintf('Enter class levels to keep (dataset has %d level%s)%s', no_levels, s_plural, s_all), title, 1, {'[]'});
27  if ~isempty(p)
28  flag_error = 0;
29  try
30  idxs = eval(p{1});
31  catch me
32  irerrordlg(me.message, 'Error');
33  flag_error = 1;
34  end;
35 
36  if ~flag_error
37  if ~isnumeric(idxs)
38  irerrordlg('Please type in a numerical vector!', 'Invalid input');
39  flag_error = 1;
40  elseif ~flag_all
41  % If all not allowed, check if user specified all
42  if isempty(idxs)
43  irerrordlg('Empty vector not allowed!', 'Invalid input');
44  flag_error = 1;
45  end;
46  end;
47  end;
48 
49  % Does not check if levels are valid, maybe that's too much, let error occur
50 
51  if ~flag_error
52  result.params = {'hierarchy', mat2str(idxs)};
53  result.flag_ok = 1;
54  break;
55  end;
56  else
57  if iscell(p)
58  % inputdlg returns an empty cell when cancelled
59  result.flag_ok = 0;
60  break;
61  else
62  irerrordlg('Please specify', 'Invalid input');
63  end;
64  end;
65 end;
66 
function ask_hierarchy(in data, in title, in flag_all)
Dataset class.
Definition: irdata.m:30
function irerrordlg(in errorstring, in dlgname)
function classlabels2cell(in classlabels, in new_hierarchy)