Mercurial > hg > ltpda
diff m-toolbox/classes/@cdata/rdivide.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/m-toolbox/classes/@cdata/rdivide.m Wed Nov 23 19:22:13 2011 +0100 @@ -0,0 +1,51 @@ +% RDIVIDE implements element division for cdata objects. +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% +% +% DESCRIPTION: RDIVIDE implements element division for two cdata objects. +% +% CALL: +% a = d1./d2 +% a = rdivide(d1,d2); +% +% +% <a href="matlab:utils.helper.displayMethodInfo('cdata', 'rdivide')">Parameters Description</a> +% +% VERSION: $Id: rdivide.m,v 1.2 2011/04/08 08:56:34 hewitson Exp $ +% +%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% + +function varargout = rdivide(varargin) + + % get two data objects + d1 = copy(varargin{1}, nargout); + d2 = copy(varargin{2}, nargout); + + % check units + d1.yunits.simplify(); + d2.yunits.simplify(); + + % add the data + dout = applyoperator(d1,d2,'rdivide'); + + % handle units: multiply the units + dout.yunits = d1.yunits./d2.yunits; + + % handle errors + err = @(err1, err2, val1, val2) sqrt( (err1./val1).^2 + (err2./val2).^2 ) .* abs(val1./val2); + if ~isempty(d1.dy) || ~isempty(d2.dy) + if isempty(d1.dy) + d1.dy = zeros(size(d2.dy)); + end + if isempty(d2.dy) + d2.dy = zeros(size(d1.dy)); + end + dout.dy = err(d1.dy, d2.dy, d1.y, d2.y); + else + dout.dy = []; + end + + % Single output + varargout{1} = dout; + +end +