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

1 回表示 (過去 30 日間)
Catalytic Kys
Catalytic Kys 2019 年 10 月 15 日
コメント済み: Catalytic Kys 2019 年 10 月 15 日
% 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

採用された回答

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSurrogate Optimization についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by