comparison m-toolbox/classes/@data2D/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 % 2D data objects.
6 %
7 % CALL: d = applyoperator(d1, d2, pl)
8 %
9 % INPUTS: d1 - a data2D object (tsdata, fsdata, xydata)
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.20 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('### data2D/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') && isa(objs{2}, 'data2D')
33 if numel(objs{1}.y) > 1
34 dout = objs{1};
35 elseif numel(objs{2}.y) > 1
36 dout = objs{2};
37 else
38 dout = objs{1};
39 end
40 elseif isa(objs{1}, 'data2D') && isa(objs{2}, 'cdata')
41 dout = objs{1};
42 else
43 %%% The first object in objs could not be a cdata because
44 %%% then calls MATLAB cdata/applyoperator
45 error('### Could/should not happen. Class obj1 [%s] class obj2 [%s]', class(objs{1}), class(objs{2}))
46 end
47
48 % Here we make some checks
49 s1 = size(objs{1}.y);
50 s2 = size(objs{2}.y);
51 trans = false;
52
53 % The exponent size should be the same OR one of the two should be 1
54 if ~isequal(s1, s2)
55 if isequal(s1, flipdim(s2, 2))
56 % We will need to transpose one vector
57 trans = true;
58 elseif ~isequal(s1, [1 1]) && ~isequal(s2, [1 1])
59 error('### Mismatch between the data and the exponent size')
60 end
61 end
62
63 % Calculate the uncertainty
64 if ~isempty(objs{1}.dy)
65 switch op
66 case 'power'
67 if trans
68 dout.dy = objs{1}.dy .* abs(objs{2}.y' .* objs{1}.y.^(objs{2}.y'-1));
69 else
70 dout.dy = objs{1}.dy .* abs(objs{2}.y .* objs{1}.y.^(objs{2}.y-1));
71 end
72 otherwise
73 end
74 end
75
76 % Finally, apply the operator to the data
77 if trans
78 dout.y = feval(op, objs{1}.y, objs{2}.y');
79 else
80 dout.y = feval(op, objs{1}.y, objs{2}.y);
81 end
82
83 varargout{1} = dout;
84 end
85
86