comparison m-toolbox/classes/@data2D/applymethod.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 % APPLYMETHOD applys the given method to the input 2D data.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: APPLYMETHOD applys the given method to the input 2D data.
5 %
6 % CALL: pl = applymethod(d, pl)
7 % pl = applymethod(d, pl, fcns)
8 %
9 % INPUTS: d - a 2D data object (tsdata, fsdata, xydata)
10 % pl - a plist of configuration options
11 % fcns - function handle(s) for the evaluation of the uncertainty
12 % (alone or in a cell array)
13 %
14 % PARAMETERS:
15 %
16 % 'method' - the method to apply to the data
17 % 'axis' - which axis vector to apply the method to. Possible values
18 % are: 'X', 'Y', 'XY' [default: 'Y']
19 % 'dim' - the dimension of the chosen vector to apply the method
20 % to. This is necessary for functions like mean() when
21 % applied to matrices held in cdata objects. For tsdata,
22 % fsdata or xydata, this option has no effect.
23 % [default: 1]
24 % 'option' - any additional option to pass to the method.
25 %
26 % VERSION: $Id: applymethod.m,v 1.15 2011/04/17 09:13:18 hewitson Exp $
27 %
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29
30 function pl = applymethod(ds, pl, method, getDefaultPlist, varargin)
31
32 % Get function handles
33 dxFcn = {};
34 for jj = 1:numel(varargin)
35 if isa(varargin{jj}, 'function_handle')
36 dxFcn = varargin{jj};
37 end
38 if iscell(varargin{jj})
39 list = varargin{jj};
40 if ~isempty(list) && isa(list{1}, 'function_handle')
41 dxFcn = list{1};
42 end
43 end
44 end
45
46 pl = applyDefaults(getDefaultPlist('2D'), pl);
47
48 % Get the axis we are dealing with
49 axis = find(pl, 'axis');
50 % Get the dimension to operate along
51 dim = find(pl, 'dim');
52 % Get any additional option
53 opt = find(pl, 'option');
54
55 % Loop over data objects
56 for jj=1:numel(ds)
57 switch lower(axis)
58 case 'x'
59 if ~isempty(ds(jj).dx) && ~isempty(dxFcn)
60 ds(jj).dx = feval(dxFcn, ds(jj).getX, ds(jj).dx);
61 else
62 ds(jj).dx = [];
63 end
64 ds(jj).x = apply(ds(jj).getX, method, dim, opt);
65 case 'y'
66 if ~isempty(ds(jj).dy) && ~isempty(dxFcn)
67 ds(jj).dy = feval(dxFcn, ds(jj).y, ds(jj).dy);
68 else
69 ds(jj).dy = [];
70 end
71 ds(jj).y = apply(ds(jj).y, method, dim, opt);
72 case 'xy'
73 if ~isempty(ds(jj).dx) && ~isempty(dxFcn)
74 ds(jj).dx = feval(dxFcn, ds(jj).getX, ds(jj).dx);
75 else
76 ds(jj).dx = [];
77 end
78 if ~isempty(ds(jj).dy) && ~isempty(dxFcn)
79 ds(jj).dy = feval(dxFcn, ds(jj).y, ds(jj).dy);
80 else
81 ds(jj).dy = [];
82 end
83 ds(jj).x = apply(ds(jj).getX, method, dim, opt);
84 ds(jj).y = apply(ds(jj).y, method, dim, opt);
85 otherwise
86 error('### Unsupported axis ''%s'' to operate on.', axis);
87 end
88 end
89
90 end
91
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
93 % Local Functions %
94 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
95
96 %-----------------------------------------------
97 % Apply method to the vector v
98 %-----------------------------------------------
99 function v = apply(v, method, dim, opt)
100 if ~isempty(dim) && ~isempty(opt)
101 % User supplied a dimension and an option
102 v = feval(method, v, dim, opt);
103 elseif ~isempty(dim)
104 % User supplied only a dimension
105 v = feval(method, v, dim);
106 elseif ~isempty(opt)
107 % User supplied only an option
108 v = feval(method, v, opt);
109 else
110 % User supplied only a method
111 v = feval(method, v);
112 end
113 end
114