ExcludeIntervals - Exclude intersecting intervals. Given two lists of intervals, exclude from the first list those intervals that intersect with one or more of the intervals in the second list. USAGE [intervals,indices] = ExcludeIntervals(intervals1,intervals2,<options>) intervals1 list of reference intervals intervals2 list of intervals to exclude <options> optional list of property-value pairs (see table below) ========================================================================= Properties Values ------------------------------------------------------------------------- 'strict' intervals with common bounds are as intersecting ('on') or disjoint ('off') (default = 'off') ========================================================================= OUTPUT intervals non-intersecting intervals indices indices of these intervals in the original list SEE See also ConsolidateIntervals, SubtractIntervals, InIntervals, Restrict, FindInInterval, CountInIntervals, PlotIntervals.
0001 function [intervals,indices] = ExcludeIntervals(intervals1,intervals2,varargin) 0002 0003 %ExcludeIntervals - Exclude intersecting intervals. 0004 % 0005 % Given two lists of intervals, exclude from the first list those intervals 0006 % that intersect with one or more of the intervals in the second list. 0007 % 0008 % USAGE 0009 % 0010 % [intervals,indices] = ExcludeIntervals(intervals1,intervals2,<options>) 0011 % 0012 % intervals1 list of reference intervals 0013 % intervals2 list of intervals to exclude 0014 % <options> optional list of property-value pairs (see table below) 0015 % 0016 % ========================================================================= 0017 % Properties Values 0018 % ------------------------------------------------------------------------- 0019 % 'strict' intervals with common bounds are as intersecting ('on') 0020 % or disjoint ('off') (default = 'off') 0021 % ========================================================================= 0022 % 0023 % OUTPUT 0024 % 0025 % intervals non-intersecting intervals 0026 % indices indices of these intervals in the original list 0027 % 0028 % SEE 0029 % 0030 % See also ConsolidateIntervals, SubtractIntervals, InIntervals, Restrict, 0031 % FindInInterval, CountInIntervals, PlotIntervals. 0032 0033 0034 % Copyright (C) 2004-2011 by Michaƫl Zugaro 0035 % 0036 % This program is free software; you can redistribute it and/or modify 0037 % it under the terms of the GNU General Public License as published by 0038 % the Free Software Foundation; either version 3 of the License, or 0039 % (at your option) any later version. 0040 0041 % Default values 0042 strict = 'off'; 0043 0044 if nargin < 2, 0045 error('Incorrect number of parameters (type ''help <a href="matlab:help ExcludeIntervals">ExcludeIntervals</a>'' for details).'); 0046 end 0047 0048 if mod(length(varargin),2) ~= 0, 0049 error('Incorrect number of parameters (type ''help <a href="matlab:help ExcludeIntervals">ExcludeIntervals</a>'' for details).'); 0050 end 0051 0052 % Parse options 0053 for i = 1:2:length(varargin), 0054 if ~ischar(varargin{i}), 0055 error(['Parameter ' num2str(i+firstIndex) ' is not a property (type ''help <a href="matlab:help ExcludeIntervals">ExcludeIntervals</a>'' for details).']); 0056 end 0057 switch(lower(varargin{i})), 0058 case 'strict', 0059 strict = lower(varargin{i+1}); 0060 if ~isastring(strict,'on','off'), 0061 error('Incorrect value for property ''strict'' (type ''help <a href="matlab:help ExcludeIntervals">ExcludeIntervals</a>'' for details).'); 0062 end 0063 otherwise, 0064 error(['Unknown property ''' num2str(varargin{i}) ''' (type ''help <a href="matlab:help ExcludeIntervals">ExcludeIntervals</a>'' for details).']); 0065 end 0066 end 0067 0068 intervals = []; 0069 indices = []; 0070 if strcmp(strict,'on'), 0071 for i = 1:size(intervals1,1), 0072 % List all intervals (to exclude) that overlap with the current interval 0073 intersect = (intervals1(i,1) <= intervals2(:,1) & intervals1(i,2) > intervals2(:,1)) ... 0074 | (intervals1(i,1) >= intervals2(:,1) & intervals1(i,2) <= intervals2(:,2)) ... 0075 | (intervals1(i,1) < intervals2(:,2) & intervals1(i,2) >= intervals2(:,2)); 0076 % Include current interval? 0077 if sum(intersect) == 0, 0078 intervals = [intervals;intervals1(i,:)]; 0079 indices = [indices;i]; 0080 end 0081 end 0082 else 0083 for i = 1:size(intervals1,1), 0084 % List all intervals (to exclude) that overlap with the current interval 0085 intersect = (intervals1(i,1) <= intervals2(:,1) & intervals1(i,2) >= intervals2(:,1)) ... 0086 | (intervals1(i,1) >= intervals2(:,1) & intervals1(i,2) <= intervals2(:,2)) ... 0087 | (intervals1(i,1) <= intervals2(:,2) & intervals1(i,2) >= intervals2(:,2)); 0088 % Include current interval? 0089 if sum(intersect) == 0, 0090 intervals = [intervals;intervals1(i,:)]; 0091 indices = [indices;i]; 0092 end 0093 end 0094 end