Mercurial > hg > ltpda
view m-toolbox/classes/@data2D/plus.m @ 37:a4b7ceae0403 database-connection-manager
Show backtrace on unit test errors
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Mon, 05 Dec 2011 16:20:06 +0100 |
parents | f0afece42f48 |
children |
line wrap: on
line source
% PLUS implements addition operator for data2D objects. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DESCRIPTION: PLUS implements addition operator for two data2D objects. % % CALL: % a = d1+d2 % a = plus(d1,d2); % % % <a href="matlab:utils.helper.displayMethodInfo('data2D', 'plus')">Parameters Description</a> % % VERSION: $Id: plus.m,v 1.2 2011/04/08 08:56:36 hewitson Exp $ % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% function varargout = plus(varargin) % get two data objects d1 = copy(varargin{1}, nargout); d2 = copy(varargin{2}, nargout); % check units d1.yunits.simplify(); d2.yunits.simplify(); d1.xunits.simplify(); d2.xunits.simplify(); if ~isempty(d1.yunits.strs) && ~isempty(d2.yunits.strs) && d1.yunits ~= d2.yunits error('### When adding two data objects, the yunits must be the same'); end if ~isempty(d1.xunits.strs) && ~isempty(d2.xunits.strs) && d1.xunits ~= d2.xunits error('### When adding two data objects, the xunits must be the same'); end % add the data dout = applyoperator(d1,d2,'plus'); % handle units: since both are the same, we take the first non-empty unit if isempty(d1.yunits.strs) dout.yunits = d2.yunits; else dout.yunits = d1.yunits; end if isempty(d1.xunits.strs) dout.xunits = d2.xunits; else dout.xunits = d1.xunits; end % handle errors err = @(err1, err2, val1, val2) sqrt(err1 .^2 + err2.^2); 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 if ~isempty(d1.dx) || ~isempty(d2.dx) if isempty(d1.dx) d1.dx = zeros(size(d2.dx)); end if isempty(d2.dx) d2.dx = zeros(size(d1.dx)); end dout.dx = err(d1.dx, d2.dx, d1.x, d2.x); else dout.dx = []; end % Single output varargout{1} = dout; end