Mercurial > hg > ltpda
comparison m-toolbox/classes/@cdata/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 cdata. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: APPLYMETHOD applys the given method to the input cdata. | |
5 % | |
6 % CALL: pl = applymethod(d, pl) | |
7 % pl = applymethod(d, pl, fcns) | |
8 % | |
9 % INPUTS: d - a cdata object | |
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 % 'dim' - the dimension of the chosen vector to apply the method | |
18 % to. This is necessary for functions like mean() when | |
19 % applied to matrices held in cdata objects. [default: 1] | |
20 % 'option' - any additional option to pass to the method. | |
21 % | |
22 % VERSION: $Id: applymethod.m,v 1.12 2011/04/17 09:13:05 hewitson Exp $ | |
23 % | |
24 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
25 | |
26 function pl = applymethod(ds, pl, method, getDefaultPlist, varargin) | |
27 | |
28 % Get function handles | |
29 dxFcn = {}; | |
30 for jj = 1:numel(varargin) | |
31 if isa(varargin{jj}, 'function_handle') | |
32 dxFcn = varargin{jj}; | |
33 end | |
34 if iscell(varargin{jj}) | |
35 list = varargin{jj}; | |
36 if ~isempty(list) && isa(list{1}, 'function_handle') | |
37 dxFcn = list{1}; | |
38 end | |
39 end | |
40 end | |
41 | |
42 pl = applyDefaults(getDefaultPlist('1D'), pl); | |
43 | |
44 % Get the axis we are dealing with | |
45 axis = find(pl, 'axis'); | |
46 % Get the dimension to operate along | |
47 dim = find(pl, 'dim'); | |
48 % Get any additional option | |
49 opt = find(pl, 'option'); | |
50 | |
51 % Loop over data objects | |
52 for jj=1:numel(ds) | |
53 switch lower(axis) | |
54 case 'y' | |
55 if ~isempty(ds(jj).dy) && ~isempty(dxFcn) | |
56 ds(jj).dy = feval(dxFcn, ds(jj).y, ds(jj).dy); | |
57 else | |
58 ds(jj).dy = []; | |
59 end | |
60 ds(jj).y = apply(ds(jj).y, method, dim, opt); | |
61 otherwise | |
62 error('### Unsupported axis ''%s'' to operate on.', axis); | |
63 end | |
64 end | |
65 | |
66 end | |
67 | |
68 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
69 % Local Functions % | |
70 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
71 | |
72 %----------------------------------------------- | |
73 % Apply method to the vector v | |
74 %----------------------------------------------- | |
75 function v = apply(v, method, dim, opt) | |
76 if ~isempty(dim) && ~isempty(opt) | |
77 % User supplied a dimension and an option | |
78 v = feval(method, v, dim, opt); | |
79 elseif ~isempty(dim) | |
80 % User supplied only a dimension | |
81 v = feval(method, v, dim); | |
82 elseif ~isempty(opt) | |
83 % User supplied only an option | |
84 v = feval(method, v, opt); | |
85 else | |
86 % User supplied only a method | |
87 v = feval(method, v); | |
88 end | |
89 end | |
90 |