comparison m-toolbox/classes/@data2D/plus.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 % PLUS implements addition operator for data2D objects.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: PLUS implements addition operator for two data2D objects.
5 %
6 % CALL:
7 % a = d1+d2
8 % a = plus(d1,d2);
9 %
10 %
11 % <a href="matlab:utils.helper.displayMethodInfo('data2D', 'plus')">Parameters Description</a>
12 %
13 % VERSION: $Id: plus.m,v 1.2 2011/04/08 08:56:36 hewitson Exp $
14 %
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16
17 function varargout = plus(varargin)
18
19 % get two data objects
20 d1 = copy(varargin{1}, nargout);
21 d2 = copy(varargin{2}, nargout);
22
23 % check units
24 d1.yunits.simplify();
25 d2.yunits.simplify();
26 d1.xunits.simplify();
27 d2.xunits.simplify();
28
29 if ~isempty(d1.yunits.strs) && ~isempty(d2.yunits.strs) && d1.yunits ~= d2.yunits
30 error('### When adding two data objects, the yunits must be the same');
31 end
32 if ~isempty(d1.xunits.strs) && ~isempty(d2.xunits.strs) && d1.xunits ~= d2.xunits
33 error('### When adding two data objects, the xunits must be the same');
34 end
35
36 % add the data
37 dout = applyoperator(d1,d2,'plus');
38
39 % handle units: since both are the same, we take the first non-empty unit
40 if isempty(d1.yunits.strs)
41 dout.yunits = d2.yunits;
42 else
43 dout.yunits = d1.yunits;
44 end
45 if isempty(d1.xunits.strs)
46 dout.xunits = d2.xunits;
47 else
48 dout.xunits = d1.xunits;
49 end
50
51 % handle errors
52 err = @(err1, err2, val1, val2) sqrt(err1 .^2 + err2.^2);
53 if ~isempty(d1.dy) || ~isempty(d2.dy)
54 if isempty(d1.dy)
55 d1.dy = zeros(size(d2.dy));
56 end
57 if isempty(d2.dy)
58 d2.dy = zeros(size(d1.dy));
59 end
60 dout.dy = err(d1.dy, d2.dy, d1.y, d2.y);
61 else
62 dout.dy = [];
63 end
64 if ~isempty(d1.dx) || ~isempty(d2.dx)
65 if isempty(d1.dx)
66 d1.dx = zeros(size(d2.dx));
67 end
68 if isempty(d2.dx)
69 d2.dx = zeros(size(d1.dx));
70 end
71 dout.dx = err(d1.dx, d2.dx, d1.x, d2.x);
72 else
73 dout.dx = [];
74 end
75
76
77 % Single output
78 varargout{1} = dout;
79
80 end
81