Mercurial > hg > ltpda
comparison m-toolbox/classes/@matrix/getObjectAtIndex.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % GETOBJECTATINDEX index into the inner objects of one matrix object. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: GETOBJECTATINDEX index into the inner objects of one matrix object. | |
5 % | |
6 % CALL: b = getObjectAtIndex(m, i) | |
7 % b = getObjectAtIndex(m, i, j) | |
8 % b = m.getObjectAtIndex(plist('I', i)) | |
9 % b = m.getObjectAtIndex(plist('I', i, 'J', j)) | |
10 % | |
11 % <a href="matlab:utils.helper.displayMethodInfo('matrix', 'getObjectAtIndex')">Parameters Description</a> | |
12 % | |
13 % VERSION: $Id: getObjectAtIndex.m,v 1.11 2011/05/22 22:15:03 mauro Exp $ | |
14 % | |
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
16 | |
17 | |
18 function varargout = getObjectAtIndex(varargin) | |
19 | |
20 % Check if this is a call for parameters | |
21 if utils.helper.isinfocall(varargin{:}) | |
22 varargout{1} = getInfo(varargin{3}); | |
23 return | |
24 end | |
25 | |
26 if nargout == 0 | |
27 error('### getObjectAtIndex cannot be used as a modifier. Please give an output variable.'); | |
28 end | |
29 | |
30 import utils.const.* | |
31 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
32 | |
33 % Collect input variable names | |
34 in_names = cell(size(varargin)); | |
35 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
36 | |
37 % Collect all 'ltpda_uoh' objects and plists | |
38 [mobjs, obj_invars, rest] = utils.helper.collect_objects(varargin(:), 'matrix', in_names); | |
39 [pl, pl_invars, rest] = utils.helper.collect_objects(rest(:), 'plist', in_names); | |
40 | |
41 | |
42 if numel(mobjs) > 1 | |
43 error('### %s only supports a single input matrix object.', mfilename); | |
44 end | |
45 | |
46 % Combine plists | |
47 pl = combine(pl, getDefaultPlist); | |
48 | |
49 % Get indices | |
50 idxi = find(pl, 'i'); | |
51 idxj = find(pl, 'j'); | |
52 if isempty(idxi) || isempty(idxj) | |
53 % go through the other inputs | |
54 for jj = 1:numel(rest) | |
55 if isnumeric(rest{jj}) && isempty(idxi) | |
56 idxi = rest{jj}; | |
57 elseif isnumeric(rest{jj}) && isempty(idxj) | |
58 idxj = rest{jj}; | |
59 end | |
60 end | |
61 end | |
62 | |
63 if isempty(idxi) && isempty(idxj) | |
64 error('### Please provide an index of index pair.'); | |
65 end | |
66 | |
67 % Now index with either (i) or (i,j) | |
68 if isempty(idxj) | |
69 for kk = 1:numel(idxi) | |
70 aout(kk) = copy(mobjs.objs(idxi(kk)), true); | |
71 hpl = pl.pset('i', idxi(kk)); | |
72 if isempty(aout(kk).name) | |
73 aout(kk).setName(sprintf('%s(%s)', mobjs.name, num2str(idxi(kk)))); | |
74 end | |
75 aout(kk).addHistory(getInfo('None'), hpl, obj_invars(1), mobjs.hist); | |
76 end | |
77 else | |
78 for ii = 1:numel(idxi) | |
79 for jj = 1:numel(idxj) | |
80 aout(ii*jj) = copy(mobjs.objs(idxi(ii), idxj(jj)), true); | |
81 hpl = pl.pset('i', idxi(ii)); | |
82 hpl = pl.pset('j', idxj(jj)); | |
83 if isempty(aout(ii*jj).name) | |
84 aout(ii*jj).setName(sprintf('%s(%s,%s)', mobjs.name, num2str(idxi(ii)), num2str(idxj(jj)))); | |
85 end | |
86 aout(ii*jj).addHistory(getInfo('None'), hpl, obj_invars(1), mobjs.hist); | |
87 end | |
88 end | |
89 end | |
90 | |
91 % Set output | |
92 varargout{1} = aout; | |
93 end | |
94 | |
95 %-------------------------------------------------------------------------- | |
96 % Get Info Object | |
97 %-------------------------------------------------------------------------- | |
98 function ii = getInfo(varargin) | |
99 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
100 sets = {}; | |
101 pl = []; | |
102 else | |
103 sets = {'Default'}; | |
104 pl = getDefaultPlist(); | |
105 end | |
106 % Build info object | |
107 ii = minfo(mfilename, 'matrix', 'ltpda', utils.const.categories.helper, '$Id: getObjectAtIndex.m,v 1.11 2011/05/22 22:15:03 mauro Exp $', sets, pl); | |
108 ii.setModifier(false); | |
109 end | |
110 | |
111 %-------------------------------------------------------------------------- | |
112 % Get Default Plist | |
113 %-------------------------------------------------------------------------- | |
114 function plout = getDefaultPlist() | |
115 persistent pl; | |
116 if ~exist('pl', 'var') || isempty(pl) | |
117 pl = buildplist(); | |
118 end | |
119 plout = pl; | |
120 end | |
121 | |
122 function plo = buildplist() | |
123 | |
124 plo = plist(); | |
125 | |
126 p = param({'I', 'The I index of the inner object vector or matrix.'}, paramValue.EMPTY_DOUBLE); | |
127 plo.append(p); | |
128 | |
129 p = param({'J', 'The J index of the inner object matrix.'}, paramValue.EMPTY_DOUBLE); | |
130 plo.append(p); | |
131 | |
132 end | |
133 |