Mercurial > hg > ltpda
comparison m-toolbox/classes/@cdata/applyoperator.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 % APPLYOPERATOR applys the given operator to the two input data objects. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: APPLYOPERATOR applys the given operator to the two input | |
5 % cdata objects. | |
6 % | |
7 % CALL: d = applyoperator(d1, d2, pl) | |
8 % | |
9 % INPUTS: d1 - a cdata object | |
10 % d2 - a ltpda_data object (cdata, tsdata, fsdata, xydata) | |
11 % pl - a plist of configuration options | |
12 % | |
13 % PARAMETERS: 'op' - the operator to apply, e.g. 'power' | |
14 % | |
15 % VERSION: $Id: applyoperator.m,v 1.15 2011/02/18 16:48:51 ingo Exp $ | |
16 % | |
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
18 | |
19 function varargout = applyoperator(varargin) | |
20 | |
21 % Get the objects we have in the correct order | |
22 objs = varargin(1:2); | |
23 | |
24 % Get the operator to apply | |
25 op = varargin{3}; | |
26 | |
27 if numel(objs) ~= 2 | |
28 error('### cdata/applyoperator requires two input data objects to work on.'); | |
29 end | |
30 | |
31 % Decide the type of the output object | |
32 if isa(objs{1}, 'data2D') | |
33 %%% The first object in objs could not be a data2D because | |
34 %%% then calls MATLAB data2D/applyoperator | |
35 error('### Could/should not happen. Class obj1 [%s] class obj2 [%s]', class(objs{1}), class(objs{2})) | |
36 elseif isa(objs{2}, 'data2D') | |
37 dout = objs{2}; | |
38 else | |
39 dout = objs{1}; | |
40 end | |
41 | |
42 | |
43 % Here we make some checks | |
44 s1 = size(objs{1}.y); | |
45 s2 = size(objs{2}.y); | |
46 trans = false; | |
47 | |
48 % The exponent size should be the same OR one of the two should be 1 | |
49 if ~isequal(s1, s2) | |
50 if isequal(s1, flipdim(s2, 2)) | |
51 % We will need to transpose one vector | |
52 trans = true; | |
53 elseif ~isequal(s1, [1 1]) && ~isequal(s2, [1 1]) | |
54 error('### Mismatch between the data and the exponent size') | |
55 end | |
56 end | |
57 | |
58 % Calculate the uncertainty | |
59 if ~isempty(objs{1}.dy) | |
60 switch op | |
61 case 'power' | |
62 if trans | |
63 dout.dy = objs{1}.dy .* abs(objs{2}.y' .* objs{1}.y.^(objs{2}.y'-1)); | |
64 else | |
65 dout.dy = objs{1}.dy .* abs(objs{2}.y .* objs{1}.y.^(objs{2}.y-1)); | |
66 end | |
67 otherwise | |
68 end | |
69 end | |
70 | |
71 % Finally, apply the operator to the data | |
72 if trans | |
73 dout.y = feval(op, objs{1}.y, objs{2}.y'); | |
74 else | |
75 dout.y = feval(op, objs{1}.y, objs{2}.y); | |
76 end | |
77 | |
78 varargout{1} = dout; | |
79 end | |
80 | |
81 |