comparison m-toolbox/classes/@ao/compute.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 % COMPUTE performs the given operations on the input AOs.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: COMPUTE performs the given operations on the input AOs.
5 %
6 % This is a transparent wrapper for the user selected operations and as such
7 % doesn't add history.
8 %
9 % CALL: b = compute(a)
10 % b = compute(a, pl)
11 % b = compute(a, 'a(1) + a(2)./a(3)')
12 % b = compute(a, {'a(1) + a(2)./a(3)', 'log10(a(1))'})
13 %
14 % PARAMETERS: 'Operations' - a string array describing the operations to
15 % be performed. The input AOs are collected
16 % together into a vector called 'a' and as
17 % such should be so represented in your
18 % operation description.
19 %
20 % If no operation is input, then the output is just a copy of the inputs.
21 %
22 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'compute')">Parameters Description</a>
23 %
24 % EXAMPLES: 1) Add the two AOs, x and y, together
25 % >> b = compute(x,y, plist('Operations', 'a(1) + a(2)'))
26 % or
27 % >> b = compute(x,y, 'a(1) + a(2)')
28 %
29 % 2) Perform two operations such that the output, b, contains two AOs
30 % >> b = compute([x y], z, plist('Operations', {'2.*a(3)./a(1)', 'a(2)-a(1)'}))
31 %
32 % VERSION: $Id: compute.m,v 1.21 2011/04/08 08:56:18 hewitson Exp $
33 %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35
36 function varargout = compute(varargin)
37
38 % Check if this is a call for parameters
39 if utils.helper.isinfocall(varargin{:})
40 varargout{1} = getInfo(varargin{3});
41 return
42 end
43
44 import utils.const.*
45 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
46
47 % Collect input variable names
48 in_names = cell(size(varargin));
49 for ii = 1:nargin,in_names{ii} = inputname(ii);end
50
51 % Collect all AOs and plists
52 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
53 [pl, pl_invars] = utils.helper.collect_objects(varargin(:), 'plist', in_names);
54
55 if nargout == 0
56 error('### compute cannot be used as a modifier. Please give an output variable.');
57 end
58
59 % Decide on a deep copy or a modify
60 a = copy(as, nargout);
61
62 % combine plists
63 pl = parse(pl, getDefaultPlist());
64
65 % Look for plist of input char
66 ops = '';
67 if ischar(varargin{end})
68 ops = varargin{end};
69 elseif iscell(varargin{end})
70 ops = varargin{end};
71 else
72 ops = find(pl, 'Operations');
73 end
74
75 % Check we have a cell array
76 if ischar(ops)
77 ops = {ops};
78 end
79
80 % Loop over operations
81 bs(length(ops),1) = ao;
82 for jj=1:length(ops)
83 % evaluate this operation
84 if ops{jj}(end) ~= ';'
85 ops{jj}(end+1) = ';';
86 end
87 bs(jj) = eval(ops{jj});
88 end
89
90 % Set outputs
91 varargout{1} = bs;
92 end
93
94 %--------------------------------------------------------------------------
95 % Get Info Object
96 %--------------------------------------------------------------------------
97 function ii = getInfo(varargin)
98 if nargin == 1 && strcmpi(varargin{1}, 'None')
99 sets = {};
100 pl = [];
101 else
102 sets = {'Default'};
103 pl = getDefaultPlist;
104 end
105 % Build info object
106 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: compute.m,v 1.21 2011/04/08 08:56:18 hewitson Exp $', sets, pl);
107 ii.setModifier(false);
108 end
109
110 %--------------------------------------------------------------------------
111 % Get Default Plist
112 %--------------------------------------------------------------------------
113
114 function plout = getDefaultPlist()
115 persistent pl;
116 if exist('pl', 'var')==0 || isempty(pl)
117 pl = buildplist();
118 end
119 plout = pl;
120 end
121
122 function pl = buildplist()
123 pl = plist({'Operations', 'A string describing the operations on the vector ''a'' of AOs'}, {1, {'a'}, paramValue.OPTIONAL});
124 end
125 % END
126
127