MINUS overloads - operator for time objects. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% DESCRIPTION: MINUS overloads - operator for analysis objects. This function subtracts a time in seconds from a time object. It is possible to define the subtrahend as a string, a vector of numbers, an ao containing a vector of numbers, or a time object. CALL: t2 = t1 - value (in seconds) sec = t1 - t2; EXAMPLES: >> t1 = time('2007-07-01 12:23:33'); >> t2 = t1 - [30 10]; >> t2 = t1 - '30'; >> t2 = t1 - ao(plist('vals',[30 10])); >> seconds = t1 - t2; VERSION: $Id: minus.html,v 1.12 2008/03/31 10:27:40 hewitson Exp $ HISTORY: 03-08-2007 Diepholz Creation %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0001 function res = minus(varargin) 0002 % MINUS overloads - operator for time objects. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: MINUS overloads - operator for analysis objects. 0007 % This function subtracts a time in seconds from a time object. 0008 % It is possible to define the subtrahend as a string, 0009 % a vector of numbers, an ao containing a vector of numbers, 0010 % or a time object. 0011 % 0012 % CALL: t2 = t1 - value (in seconds) 0013 % sec = t1 - t2; 0014 % 0015 % EXAMPLES: >> t1 = time('2007-07-01 12:23:33'); 0016 % >> t2 = t1 - [30 10]; 0017 % >> t2 = t1 - '30'; 0018 % >> t2 = t1 - ao(plist('vals',[30 10])); 0019 % >> seconds = t1 - t2; 0020 % 0021 % VERSION: $Id: minus.html,v 1.12 2008/03/31 10:27:40 hewitson Exp $ 0022 % 0023 % HISTORY: 03-08-2007 Diepholz 0024 % Creation 0025 % 0026 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0027 0028 VERSION = '$Id: minus.html,v 1.12 2008/03/31 10:27:40 hewitson Exp $'; 0029 CATEGORY = 'Arithmetic Operator'; 0030 0031 % 'Params' Call 0032 if nargin == 2 0033 if isa(varargin{1}, 'time') && ischar(varargin{2}) 0034 in = char(varargin{2}); 0035 if strcmp(in, 'Params') 0036 res = plist(); 0037 return 0038 elseif strcmp(in, 'Version') 0039 res = VERSION; 0040 return 0041 elseif strcmp(in, 'Category') 0042 res = CATEGORY; 0043 return 0044 end 0045 end 0046 end 0047 0048 % Collects the input values 0049 t1 = varargin{1}; 0050 t2 = varargin{2}; 0051 0052 0053 %%%%% >> t2 = t1 - ao(30); %%%%% 0054 if isa(t2, 'ao') 0055 t2 = t2.data.y; 0056 end 0057 0058 %%%%% >> t2 = t1 - '30'; %%%%% 0059 if ischar(t2) 0060 t2 = str2double(t2); 0061 end 0062 0063 %%%%% >> t2 = t1 - 30; %%%%% 0064 res = []; 0065 % Loop over the list of inputs 0066 if isnumeric(t2) 0067 tn = time; 0068 for jj = 1 : length(t2) 0069 res = [res;t1]; 0070 res(jj) = set(res(jj), ... 0071 'utc_epoch_milli', t1.utc_epoch_milli - t2(jj)*1000, ... 0072 'created', tn.time_str); 0073 end 0074 %%%%% >> number = t1 - t2; %%%%% 0075 elseif isa(t2, 'time') 0076 res = (t1.utc_epoch_milli - t2.utc_epoch_milli)/1000; 0077 else 0078 error ('### Unknown minus-operation to a time object.'); 0079 end 0080