Rewrote intersect function.

parent 81e563b2
function C = intersect(A,B) % --*-- Unitary tests --*--
function q = intersect(o, p) % --*-- Unitary tests --*--
%@info:
%! @deftypefn {Function File} {@var{C} =} intersect (@var{A},@var{B})
%! @anchor{@dates/intersect}
%! @sp 1
%! C of B and A.
%! if A and B are not disjoints.
%! @sp 2
%! @strong{Inputs}
%! @sp 1
%! @table @ @var
%! @item A
%! @ref{dates} object.
%! @item B
%! @ref{dates} object.
%! @end table
%! @sp 2
%! @strong{Outputs}
%! @sp 1
%! @table @ @var
%! @item C
%! @ref{dates} object.
%! @end table
%! @end deftypefn
%@eod:
% Copyright (C) 2013 Dynare Team
% Overloads intersect function for dates objects.
%
% INPUTS
% - o [dates]
% - p [dates]
%
% This file is part of Dynare.
% OUTPUTS
% - q [dates] All the common elements in o and p.
% Copyright (C) 2013-2014 Dynare Team
%
% Dynare is free software: you can redistribute it and/or modify
% This code is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% Dynare is distributed in the hope that it will be useful,
% Dynare dates submodule is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
......@@ -42,34 +24,34 @@ function C = intersect(A,B) % --*-- Unitary tests --*--
% You should have received a copy of the GNU General Public License
% along with Dynare. If not, see <http://www.gnu.org/licenses/>.
if ~isa(A,'dates') || ~isa(B,'dates')
error(['dates::plus: Input arguments ''' inputname(1) ''' and ''' inputname(2) ''' must be dates objects!'])
if ~isa(o,'dates') || ~isa(p,'dates')
error('dates:intersect:ArgCheck','All input arguments must be dates objects!')
end
if eq(A,B)
C = A;
if o.length()==p.length() && o==p
q = copy(a);
return
end
if ~isequal(A.freq,B.freq)
C = dates();
if ~isequal(o.freq,p.freq)
q = dates();
return
end
if isoctave || matlab_ver_less_than('8.1.0')
time = intersect(A.time,B.time,'rows');
time = intersect(o.time,p.time,'rows');
else
time = intersect(A.time,B.time,'rows','legacy');
time = intersect(o.time,p.time,'rows','legacy');
end
C = dates();
q = dates();
if isempty(time)
return
end
C.freq = A.freq;
C.time = time;
C.ndat = rows(time);
q.freq = o.freq;
q.time = time;
q.ndat = rows(time);
%@test:1
%$ % Define some dates objects
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment