interval

PURPOSE ^

INTERVAL - compute intersection and union of interval

SYNOPSIS ^

function [is,in,un] = interval(x1,x2)

DESCRIPTION ^

INTERVAL - compute intersection and union of interval

 Intersection and union of 2 intervals.
    [IS,IN,UN] = INTERVAL(X1,X2) calculates pair-wise
    intersection IN and union UN of N pairs of
    intervals with coordinates X1 and X2 (both are
    2 by N vectors). Returns 1 by N boolean vector IS
    equal to 1 if intervals have non-empty intersection
    and 0 if they don't.

  Copyright (c) 1995 by Kirill K. Pankratov,
       kirill@plume.mit.edu.
       08/24/95

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [is,in,un] = interval(x1,x2)
0002 %INTERVAL - compute intersection and union of interval
0003 %
0004 % Intersection and union of 2 intervals.
0005 %    [IS,IN,UN] = INTERVAL(X1,X2) calculates pair-wise
0006 %    intersection IN and union UN of N pairs of
0007 %    intervals with coordinates X1 and X2 (both are
0008 %    2 by N vectors). Returns 1 by N boolean vector IS
0009 %    equal to 1 if intervals have non-empty intersection
0010 %    and 0 if they don't.
0011 %
0012 %  Copyright (c) 1995 by Kirill K. Pankratov,
0013 %       kirill@plume.mit.edu.
0014 %       08/24/95
0015 
0016  % Handle input ...........................
0017 if nargin==0, help interval, return, end
0018 if nargin==1
0019   un = x1;
0020 else
0021   un = [x1; x2];
0022 end
0023 
0024 [in,un] = sort(un);     % Sort both intervals together
0025 un = un(1:2,:)-1;
0026 is = sum(floor(un/2));  % Check for [0 0 1 1] or [1 1 0 0]
0027 is = (is==1);
0028 ii = find(in(2,:)==in(3,:));
0029 is(ii) = .5*ones(size(ii));
0030 
0031  % Extract intersection and union from sorted coordinates
0032 if nargout>1
0033   un = in([1 4],:);
0034   in = in(2:3,:);
0035   in(:,~is) = flipud(in(:,~is));
0036 end
0037

Generated on Sun 29-Mar-2009 20:22:55 by m2html © 2003