Home > atmlab > time > find_common_time.m

find_common_time

PURPOSE ^

find_common_time For which segments do the time arrays overlap?

SYNOPSIS ^

function [iv1, iv2] = find_common_time(t1, t2, interval)

DESCRIPTION ^

 find_common_time For which segments do the time arrays overlap?

 Given two vectors, gives the interval in which both overlap, +/- an
 interval.

 FORMAT

   [iv1, iv2] = find_common_time(t1, t2, interval)

 IN

   t1       vector     First time axis
   t2       vector     Second time axis
   interval number     Maximum difference to consider overlap

 OUT

   iv1      logical    Segment of t1 overlapping with t2    
   iv2      logical    Segment of t2 overlapping with t1

 $Id$

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

find_common_time.m

SOURCE CODE ^

0001 function [iv1, iv2] = find_common_time(t1, t2, interval)
0002 
0003 % find_common_time For which segments do the time arrays overlap?
0004 %
0005 % Given two vectors, gives the interval in which both overlap, +/- an
0006 % interval.
0007 %
0008 % FORMAT
0009 %
0010 %   [iv1, iv2] = find_common_time(t1, t2, interval)
0011 %
0012 % IN
0013 %
0014 %   t1       vector     First time axis
0015 %   t2       vector     Second time axis
0016 %   interval number     Maximum difference to consider overlap
0017 %
0018 % OUT
0019 %
0020 %   iv1      logical    Segment of t1 overlapping with t2
0021 %   iv2      logical    Segment of t2 overlapping with t1
0022 %
0023 % $Id$
0024 
0025 if isempty(t1) || isempty(t2)
0026     iv1 = true(size(t1));
0027     iv2 = true(size(t2));
0028     return
0029 end
0030 
0031 t1f = t1(1);
0032 t1l = t1(end);
0033 t2f = t2(1);
0034 t2l = t2(end);
0035 
0036 total_first = max([t1f t2f]) - interval;
0037 total_last = min([t1l t2l]) + interval;
0038 
0039 iv1 = (t1>total_first) & (t1<total_last);
0040 iv2 = (t2>total_first) & (t2<total_last);
0041 
0042 iv1(find(iv1, 1, 'first'):find(iv1, 1, 'last')) = true;
0043 iv2(find(iv2, 1, 'first'):find(iv2, 1, 'last')) = true;

Generated on Mon 15-Sep-2014 13:31:28 by m2html © 2005