Could anyone help me with a code to check if the time intervals intersect

2 views (last 30 days)
% This script should select the optimal time intervals, so that as many time intervals fit without intersecting each other.
clear;
close all;
clc;
list = [
10 20; % Time intervals: (start day [space] end day) (starts at day 10 ends at day 20 of the year)
9 15;
16 17;
21 100;
];
list_ordered = sortrows(list)
% Check which time intervals overlap:
% 10 20 [9 15, 16 17]
% 9 15 [10 20]
% 16 17 [10 20]
% 21 100 []
% Remove the time intervals with the most intersections:
% 9 15
% 16 17
% 21 100

Accepted Answer

Andrei Bobrov
Andrei Bobrov on 15 Oct 2019
M = sortrows(list);
out = M(sum(squeeze(any(M - permute(M,[3,2,1]) <= 0,2))) == 1:size(list,1),:);

More Answers (0)

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!