Code covered by the BSD License  

Highlights from
mydate

mydate

by

 

16 Apr 2011 (Updated )

Augments MATLAB's date/time library for improved handling of epochs and formats commonly used in GPS

mydatesec (num, is_diff, factor)
function out = mydatesec (num, is_diff, factor)
%MYDATESEC: Convert epoch interval to (decimal) seconds.
    %if (nargin < 2) || isempty(is_diff),  is_diff = false;  end  % WRONG!
    if (nargin < 2) || isempty(is_diff),  is_diff = true;  end
    if (nargin < 3) || isempty(factor),  factor = 60*60*24;  end
    if (size(num,2) > 1),  vec = num;  num = mydatenum(vec, is_diff);  end
    [factor0, num0] = mydatebase ();
    out = num;
    if ~is_diff,  out = out - num0;  end
    if (factor0 ~= factor),  out = out ./ (factor0 / factor);  end
end

%!test
%! sec = 100 * rand();
%! vec = [0 0 0  0 0 sec];
%! num = mydatenum (vec, true);
%! sec2 = mydatesec (num, true);
%! num2 = mydateseci (sec, true);
%! %[sec, sec2, sec2-sec]
%! %[num, num2, num2-num]
%! myassert(sec2, sec, -sqrt(eps()))
%! myassert(num2, num, -sqrt(eps()))

Contact us