0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % COLLECT_OBJECTS Collect objects of the required class.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % DESCRIPTION: COLLECT_OBJECTS Collect objects of the required class.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % CALL: [objs, invars, rest] = collect_objects(varargin, class_type, in_names);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 % [objs, invars] = collect_objects(varargin, class_type, in_names);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % [objs] = collect_objects(varargin, class_type, in_names);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 % [objs] = collect_objects(varargin, class_type);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % [objs] = collect_objects(varargin, '');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 % INPUTS: varargin: Cell array of objects
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % class_name: Class name of the collected objects
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 % If the class_name is empty then this function
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 % collects all objects of the same class as
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 % the first ltpda_object.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 % in_names: Cell array of corresponding variable names of
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 % the contents in varargin
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 % OUTPUTS: objs: Collection of all required class objects.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 % invars: Collection of the object names of the corresponding object.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 % rest: Rest of all other objects collected in a cell array.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 % VERSION: $Id: collect_objects.m,v 1.15 2011/04/19 16:24:36 ingo Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 % HISTORY: 08-05-07 Diepholz
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 % Creation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 function varargout = collect_objects(varargin, class_type, in_names)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 %%% collect input objects and corresponding variable names
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 %%% If the class_type is empty then collect all objects of the first ltpda object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 if isempty(class_type)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 for ii = 1:length(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 if isa(varargin{ii}, 'ltpda_obj')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 class_type = class(varargin{ii});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 % Count the number of arguments that contain this class type
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 Narg = length(varargin);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 classmatch = zeros(Narg,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 Nclass = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 for ii=1:Narg
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 if isa(varargin{ii}, class_type)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 classmatch(ii) = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 Nclass = Nclass + 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 invars = {};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 objs = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 other = {};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 for ii=1:Narg
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 vii = varargin{ii};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 if classmatch(ii)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 if Nclass == 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 objs = vii;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 if numel(vii) == 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 objs = [objs vii];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 objs = [objs reshape(vii, 1, [])];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 %%% Define the variable name only if the input names are specified.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 if nargin == 3 && nargout > 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 % It is possible for a internal-call that in_names is empty
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 % Create forthis an empty cell-array wit the size of varargin
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 if isempty(in_names)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 in_names = cell(size(varargin));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 def_name = in_names{ii};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 if isempty(def_name)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 def_name = 'unknown';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 % Memorise the variable name of the corresponding object.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 % If the object is an array or vector add the index to the variable name
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 % we choose the object name if it is not set to the default
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 % and it's not empty.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 if (numel(vii) == 1) || (numel(vii) == 0)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 if classmatch(ii)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 if ~strncmpi(vii.name, 'None', 4)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 if ~isempty(vii.name)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 def_name = vii.name;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 invars{end+1} = def_name;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 elseif classmatch(ii)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 if isa(vii, 'ltpda_uo')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 % Check the elements have all the same names
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 sameNames = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 name = vii(1).name;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 for jj=2:numel(vii)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 if ~strcmp(name, vii(jj).name)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 sameNames = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 break;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 if sameNames
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 if ~strcmpi(vii(1).name, 'None') && ~isempty(vii(1).name)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 def_name = vii(1).name;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 Nargii = size(vii,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 for jj=1:numel(vii)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 invars{end+1} = mind2subStr(def_name, Nargii,jj);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 for jj=1:numel(vii)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 invars{end+1} = vii(jj).name;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129 % The objects don't have a 'name'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 Nargii = size(vii,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 for jj=1:numel(vii)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 invars{end+1} = mind2subStr(def_name, Nargii,jj);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136 invars{end+1} = def_name;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141 if nargout > 2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 other{end+1} = vii;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148 % Collect outputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149 if nargout >= 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 varargout{1} = objs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152 if nargout >= 2
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153 varargout{2} = invars;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155 if nargout >= 3
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 varargout{3} = other;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160 %--------------------------------------------------------
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 % A much simplified special case of ind2sub to collect just
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 % the names.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164 function s = mind2subStr(name, siz, ndx)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 % Get J
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 vi = rem(ndx-1, siz) + 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168 J = (ndx-vi)/siz + 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
169
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
170 % Get I
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
171 ndx = vi;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
172 vi = rem(ndx-1, 1) + 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
173 s = sprintf('%s(%d,%d)', name, (ndx - vi) + 1,J);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
174 end
|