comparison m-toolbox/classes/@data3D/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 data3D objects.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: PLUS implements addition operator for two data3D objects.
5 %
6 % CALL:
7 % a = d1+d2
8 % a = plus(d1,d2);
9 %
10 %
11 % <a href="matlab:utils.helper.displayMethodInfo('data3D', '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.zunits.simplify();
25 d2.zunits.simplify();
26 d1.yunits.simplify();
27 d2.yunits.simplify();
28 d1.xunits.simplify();
29 d2.xunits.simplify();
30
31 if ~isempty(d1.zunits.strs) && ~isempty(d2.zunits.strs) && d1.zunits ~= d2.zunits
32 error('### When adding two data objects, the zunits must be the same');
33 end
34 if ~isempty(d1.yunits.strs) && ~isempty(d2.yunits.strs) && d1.yunits ~= d2.yunits
35 error('### When adding two data objects, the yunits must be the same');
36 end
37 if ~isempty(d1.xunits.strs) && ~isempty(d2.xunits.strs) && d1.xunits ~= d2.xunits
38 error('### When adding two data objects, the xunits must be the same');
39 end
40
41 % add the data
42 dout = applyoperator(d1,d2,'plus');
43
44 % handle units: since both are the same, we take the first non-empty unit
45 if isempty(d1.zunits.strs)
46 dout.zunits = d2.zunits;
47 else
48 dout.zunits = d1.zunits;
49 end
50 if isempty(d1.yunits.strs)
51 dout.yunits = d2.yunits;
52 else
53 dout.yunits = d1.yunits;
54 end
55 if isempty(d1.xunits.strs)
56 dout.xunits = d2.xunits;
57 else
58 dout.xunits = d1.xunits;
59 end
60
61 % handle errors
62 err = @(err1, err2) sqrt(err1 .^2 + err2.^2);
63 if ~isempty(d1.dz) || ~isempty(d2.dz)
64 if isempty(d1.dz)
65 d1.dz = zeros(size(d2.dz));
66 end
67 if isempty(d2.dz)
68 d2.dz = zeros(size(d1.dz));
69 end
70 dout.dz = err(d1.dz, d2.dz);
71 else
72 dout.dz = [];
73 end
74 if ~isempty(d1.dy) || ~isempty(d2.dy)
75 if isempty(d1.dy)
76 d1.dy = zeros(size(d2.dy));
77 end
78 if isempty(d2.dy)
79 d2.dy = zeros(size(d1.dy));
80 end
81 dout.dy = err(d1.dy, d2.dy);
82 else
83 dout.dy = [];
84 end
85 if ~isempty(d1.dx) || ~isempty(d2.dx)
86 if isempty(d1.dx)
87 d1.dx = zeros(size(d2.dx));
88 end
89 if isempty(d2.dx)
90 d2.dx = zeros(size(d1.dx));
91 end
92 dout.dx = err(d1.dx, d2.dx);
93 else
94 dout.dx = [];
95 end
96
97
98 % Single output
99 varargout{1} = dout;
100
101 end
102