Added second output argument to setdiff method.

If o and p are two dates objects, then with

[q, io] = setdiff(o, p)

we obtain in q the elements belonging to o but not to p, and io is such
that q = o(io).
parent 9b0acc73
function q = setdiff(o,p) % --*-- Unitary tests --*-- function [q, io] = setdiff(o,p) % --*-- Unitary tests --*--
% Overloads setdiff function for dates objects. % Overloads setdiff function for dates objects.
% %
% INPUTS % INPUTS
% - o [dates] % - o [dates]
% - p [dates] % - p [dates]
% %
% OUTPUTS % OUTPUTS
% - q [dates] % - q [dates] with n elements
% - io [integer] n*1 vector of integers such that q = o(io)
% %
% See also pop, remove. % See also pop, remove.
...@@ -36,26 +37,32 @@ end ...@@ -36,26 +37,32 @@ end
if isempty(p) if isempty(p)
q = copy(o); q = copy(o);
if nargout>1, io = 1:length(q); end
return return
end end
if o==p if o==p
% Return an empty dates object. % Return an empty dates object.
q = dates(o.freq); q = dates(o.freq);
if nargout>1, io = []; end
return return
end end
if isoctave || matlab_ver_less_than('8.1.0') if isoctave || matlab_ver_less_than('8.1.0')
time = setdiff(o.time,p.time,'rows'); if nargout<2
time = setdiff(o.time,p.time,'rows');
else
[time, io] = setdiff(o.time,p.time,'rows');
end
else else
time = setdiff(o.time,p.time,'rows','legacy'); if nargout<2
time = setdiff(o.time,p.time,'rows','legacy');
else
[time, io] = setdiff(o.time,p.time,'rows','legacy');
end
end end
q = dates(o.freq); q = dates(o.freq);
if isempty(time)
return
end
q.time = time; q.time = time;
%@test:1 %@test:1
......
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