IRootLab
An Open-Source MATLAB toolbox for vibrational biospectroscopy
get_varnames.m
Go to the documentation of this file.
1 %>@ingroup codegen
2 %> @file
3 %> @brief Variable names in workspace matching class
4 %>
5 %> @param classname Class to match
6 %> @param input (optional) (may be either a string with a class name or an instance of such class)
7 %> Input class to match. This is applicable only if @c classname is "block" or descendant, and is not checked,
8 %> i.e., there will be an error if you specify input but classname is not the name of a block descendant
9 %> @return A cell of string containing the names of the variables in the workspace that match @c classname
10 function vars = get_varnames(classname, input)
11 if ~iscell(classname)
12  classname = {classname};
13 end;
14 flag_input = nargin > 1 && ~isempty(input);
15 if flag_input && ischar(input)
16  input = eval([input, '();']); % Creates instance of class whose name was given by input
17 end;
18 vars0 = evalin('base', 'who');
19 n = numel(vars0);
20 
21 flag_progress = n > 100;
22 
23 if flag_progress
24  ipro = progress2_open('GET_VARNAMES', [], 0, n);
25 end;
26 
27 vars = {};
28 for i = 1:n
29  if ~ismember(get_excludevarnames(), vars0{i}) %> operational names such as 'o' are excluded from list
30  var = evalin('base', [vars0{i}, ';']);
31  if sum(arrayfun(@(cn) isa(var, cn{1}), classname)) > 0
32  if ~flag_input
33  flag_continue = 1;
34  else
35  ic = var.inputclass;
36  if ~iscell(ic)
37  ic = {ic};
38  end;
39  flag_continue = any(cellfun(@(x) isa(input, x), ic));
40  end;
41 
42  if flag_continue
43  vars{end+1} = vars0{i};
44  end;
45  end;
46  end;
47 
48  if flag_progress
49  ipro = progress2_change(ipro, [], [], i);
50  end;
51 end;
52 
53 if flag_progress
54  progress2_close(ipro);
55 end;
function progress2_change(in prgrss, in title, in perc, in i, in n)
function progress2_open(in title, in perc, in i, in n)
function get_excludevarnames()
Base Block class.
Definition: block.m:2
function get_varnames(in classname, in input)
function progress2_close(in prgrss)
Property inputclass
Definition: block.m:11
Analysis Session (AS) base class.
Definition: as.m:6