KerMor  0.9
Model order reduction for nonlinear dynamical systems and nonlinear approximation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
FindInstance.m
Go to the documentation of this file.
1 
2 
3 /* (Autoinserted by mtoc++)
4  * This source code has been filtered by the mtoc++ executable,
5  * which generates code that can be processed by the doxygen documentation tool.
6  *
7  * On the other hand, it can neither be interpreted by MATLAB, nor can it be compiled with a C++ compiler.
8  * Except for the comments, the function bodies of your M-file functions are untouched.
9  * Consequently, the FILTER_SOURCE_FILES doxygen switch (default in our Doxyfile.template) will produce
10  * attached source files that are highly readable by humans.
11  *
12  * Additionally, links in the doxygen generated documentation to the source code of functions and class members refer to
13  * the correct locations in the source code browser.
14  * However, the line numbers most likely do not correspond to the line numbers in the original MATLAB source files.
15  */
16 
17 function [PrintTablet , cellmatches , parents , celllocations ] = FindInstance(handle obj,char type,varargin) {
18 
19 
20  if ~isa(obj, " handle ") && ~isstruct(obj)
21  error(" The argument must either be a handle class or a struct. ");
22  end
23 
24  matches = [];
25  visited = [];
26  parents = [];
27  locations = [];
28  t = PrintTable(" Instances of '%s' in %s (%s) ",...
29  type,inputname(1),class(obj));
30  t.HasHeader= true;
31  t.addRow(" Location "," Class "," ID "," Parent ",varargin[:]);
32 
33  warning(" off "," MATLAB:structOnObject ");
34  findinst_recur(obj, inputname(1), true);
35  warning(" on "," MATLAB:structOnObject ");
36 
37  function findinst_recur(obj, lvl, checkloop)
38  if checkloop && any(cellfun(@(o)isequal(o,obj),visited))
39  return;
40  end
41 
42  if numel(obj) > 1
43  if iscell(obj)
44  for l = 1:length(obj)
45  findinst_recur(obj[l], sprintf(" %s{%d} ",lvl,l), false);
46  end
47  else
48  for l = 1:length(obj)
49  findinst_recur(obj(l), sprintf(" %s(%d) ",lvl,l), false);
50  end
51  end
52  else
53  if isa(obj," handle ")
54  try
55  os = struct(obj);
56  catch ME
57 /* t.addRow(lvl,class(obj),'error',class(obj),{});
58  * return; */
59  end
60  elseif isstruct(obj)
61  os = obj;
62  end
63  fn = fieldnames(os);
64  for idx = 1:length(fn)
65  if ~isempty(os.(fn[idx]))
66  prop = os.(fn[idx]);
67  thislvl = [lvl " . " fn[idx]];
68  if isa(prop,type)
69  matches[end+1] = prop;/* #ok */
70 
71  parents[end+1] = obj;/* #ok */
72 
73  locations[end+1] = thislvl;/* #ok */
74 
75  st = " none ";
76  if any(cellfun(@(o)isequal(o," ID "),fieldnames(prop)))
77  st = prop.ID;
78  end
79  props = cell(1,length(varargin));
80  for k = 1:length(varargin)
81  if isprop(prop,varargin[k]) || isfield(prop,varargin[k])
82  props[k] = prop.(varargin[k]);
83  else
84  props[k] = " doesn "" t exist ";
85  end
86  end
87  t.addRow(thislvl,class(prop),st,class(obj),props[:]);
88  end
89  if isa(prop, " handle ") || isstruct(prop)
90  visited[end+1] = obj;/* #ok */
91 
92  findinst_recur(prop, thislvl, true);
93  end
94  end
95  end
96  end
97  end
98 
99 
100 end
101 }
A MatLab cell array or matrix.
function [ PrintTable t , cell matches , parents , cell locations ] = FindInstance(handle obj,char type, varargin)
FindInstance: Locate instances of certain classes within a class or a struct.
Definition: FindInstance.m:17
Matlab's base handle class (documentation generation substitute)
A variable number of input arguments.
PrintTable: Class that allows table-like output spaced by tabs for multiple rows. ...
Definition: PrintTable.m:17