Mercurial > hg > ltpda
comparison m-toolbox/classes/@cdata/minus.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 % MINUS implements subtraction operator for cdata objects. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: MINUS implements subtraction operator for two cdata objects. | |
5 % | |
6 % CALL: a = d1-d2 | |
7 % a = minus(d1,d2); | |
8 % | |
9 % <a href="matlab:utils.helper.displayMethodInfo('cdata', 'minus')">Parameters Description</a> | |
10 % | |
11 % VERSION: $Id: minus.m,v 1.3 2011/04/08 08:56:34 hewitson Exp $ | |
12 % | |
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
14 | |
15 function varargout = minus(varargin) | |
16 | |
17 % get two data objects | |
18 d1 = copy(varargin{1}, nargout); | |
19 d2 = copy(varargin{2}, nargout); | |
20 | |
21 % check units | |
22 d1.yunits.simplify(); | |
23 d2.yunits.simplify(); | |
24 | |
25 if ~isempty(d1.yunits.strs) && ~isempty(d2.yunits.strs) && d1.yunits ~= d2.yunits | |
26 error('### When subtracting two data objects, the yunits must be the same'); | |
27 end | |
28 | |
29 % add the data | |
30 dout = applyoperator(d1,d2,'minus'); | |
31 | |
32 % handle units: since both are the same, we take the first non-empty unit | |
33 if isempty(d1.yunits.strs) | |
34 dout.yunits = d2.yunits; | |
35 else | |
36 dout.yunits = d1.yunits; | |
37 end | |
38 | |
39 % handle errors | |
40 err = @(err1, err2) sqrt(err1 .^2 + err2.^2); | |
41 if ~isempty(d1.dy) || ~isempty(d2.dy) | |
42 if isempty(d1.dy) | |
43 d1.dy = zeros(size(d2.dy)); | |
44 end | |
45 if isempty(d2.dy) | |
46 d2.dy = zeros(size(d1.dy)); | |
47 end | |
48 dout.dy = err(d1.dy, d2.dy); | |
49 else | |
50 dout.dy = []; | |
51 end | |
52 | |
53 | |
54 % Single output | |
55 varargout{1} = dout; | |
56 | |
57 end | |
58 |