Mercurial > hg > ltpda
comparison m-toolbox/classes/@cdata/times.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 % TIMES implements element multiplication for cdata objects. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: TIMES implements element multiplication for two cdata objects. | |
5 % | |
6 % CALL: | |
7 % a = d1.*d2 | |
8 % a = times(d1,d2); | |
9 % | |
10 % | |
11 % <a href="matlab:utils.helper.displayMethodInfo('cdata', 'times')">Parameters Description</a> | |
12 % | |
13 % VERSION: $Id: times.m,v 1.2 2011/04/08 08:56:34 hewitson Exp $ | |
14 % | |
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
16 | |
17 function varargout = times(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 | |
27 % add the data | |
28 dout = applyoperator(d1,d2,'times'); | |
29 | |
30 % handle units: multiply the units | |
31 dout.yunits = d1.yunits.*d2.yunits; | |
32 | |
33 % handle errors | |
34 err = @(err1, err2, val1, val2) sqrt( (err1./val1).^2 + (err2./val2).^2 ) .* abs(val1.*val2); | |
35 if ~isempty(d1.dy) || ~isempty(d2.dy) | |
36 if isempty(d1.dy) | |
37 d1.dy = zeros(size(d2.dy)); | |
38 end | |
39 if isempty(d2.dy) | |
40 d2.dy = zeros(size(d1.dy)); | |
41 end | |
42 dout.dy = err(d1.dy, d2.dy, d1.y, d2.y); | |
43 else | |
44 dout.dy = []; | |
45 end | |
46 | |
47 % Single output | |
48 varargout{1} = dout; | |
49 | |
50 end | |
51 |