comparison m-toolbox/classes/@ao/scale.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 % SCALE scales the data in the AO by the specified factor.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: SCALE scales the data in the AO by the specified factor.
5 %
6 % CALL: bs = scale(a1,a2,a3,...,pl)
7 % bs = scale(as,pl)
8 % bs = as.scale(pl)
9 %
10 % INPUTS: aN - input analysis objects
11 % as - input analysis objects array
12 % pl - input parameter list
13 %
14 % OUTPUTS: bs - array of analysis objects, one for each input
15 %
16 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'scale')">Parameters Description</a>
17 %
18 % VERSION: $Id: scale.m,v 1.18 2011/04/08 08:56:11 hewitson Exp $
19 %
20 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
21
22 % PARAMETERS:
23 % 'factor' - the factor to scale by [default: 1]
24 % 'yunits' - set a value for the scale factor units
25 % [default: empty => output object will have the same units as input]
26 %
27 %
28
29 function varargout = scale(varargin)
30
31 import utils.const.*
32
33 % Check if this is a call for parameters
34 if utils.helper.isinfocall(varargin{:})
35 varargout{1} = getInfo(varargin{3});
36 return
37 end
38
39 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
40
41 % Collect input variable names
42 in_names = cell(size(varargin));
43 for ii = 1:nargin,in_names{ii} = inputname(ii);end
44
45 % Collect all AOs
46 [as, ao_invars,rest] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
47 [pls, invars, rest] = utils.helper.collect_objects(rest(:), 'plist');
48
49 % Get default parameters
50 pl = parse(pls, getDefaultPlist);
51
52 % Get the factor from the plist
53 factor = find(pl, 'factor');
54
55 % Get user specified yunits
56 if find(pl, 'yunits')
57 factor_units = find(pl, 'yunits');
58 else
59 factor_units = '';
60 end
61
62 if isa(factor, 'ao')
63 % If the factor is an ao, then also get the units
64 if isempty (factor_units)
65 factor_units = factor.yunits;
66 end
67 factor = factor.y;
68 end
69
70 % look in rest
71 if factor == 1 && ~isempty(rest)
72 factor = rest{1};
73 end
74
75 % now check we got a factor
76 if isempty(factor) || ~isnumeric(factor) || numel(factor) ~= 1
77 error('### The factor must be a single numeric value.');
78 end
79
80 % Set the factor to the plist.
81 % It might be that the factor was not in the plist
82 pl.pset('factor', factor);
83
84 % Decide on a deep copy or a modify
85 bs = copy(as, nargout);
86
87
88 % Apply method to all AOs
89 for kk = 1:numel(bs)
90
91 bs(kk).data.setY(bs(kk).data.y .* factor);
92 bs(kk).data.setDy(bs(kk).data.dy .* factor);
93
94 % Set yunits
95 if ~isempty(factor_units)
96 bs(kk).data.setYunits(...
97 simplify(unit(factor_units) .* bs(kk).data.yunits, ...
98 plist('prefixes', false)));
99 end
100 % set name
101 bs(kk).name = sprintf('(%s.*%g)', bs(kk).name, factor);
102 % add history
103 bs(kk).addHistory(getInfo('None'), pl, ao_invars(kk), as(kk).hist);
104 end
105
106 % Set output
107 if nargout == numel(bs) && numel(bs)>1
108 for ii = 1:numel(bs)
109 varargout{ii} = bs(ii);
110 end
111 else
112 varargout{1} = bs;
113 end
114 end
115
116 %--------------------------------------------------------------------------
117 % Get Info Object
118 %--------------------------------------------------------------------------
119 function ii = getInfo(varargin)
120 if nargin == 1 && strcmpi(varargin{1}, 'None')
121 sets = {};
122 pl = [];
123 else
124 sets = {'Default'};
125 pl = getDefaultPlist;
126 end
127 % Build info object
128 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.op, '$Id: scale.m,v 1.18 2011/04/08 08:56:11 hewitson Exp $', sets, pl);
129 end
130
131 %--------------------------------------------------------------------------
132 % Get Default Plist
133 %--------------------------------------------------------------------------
134 function plout = getDefaultPlist()
135 persistent pl;
136 if exist('pl', 'var')==0 || isempty(pl)
137 pl = buildplist();
138 end
139 plout = pl;
140 end
141
142 function pl = buildplist()
143
144 pl = plist();
145
146 p = param({'factor',['The factor to scale by.<br>', ...
147 'It can be a double or an ao. In this latter case, the units will be multiplied as well']}, paramValue.DOUBLE_VALUE(1));
148 pl.append(p);
149
150 p = param({'yunits', ['Set a value for the scale factor units;<br>', ...
151 'empty => output object will have the same units as input.<br>', ...
152 'Note: these units will override those from the scale factor, if the user specified it as an ao!']}, paramValue.EMPTY_STRING);
153 pl.append(p);
154
155 end
156
157 % END