Delete overlaping intervals in matrix
Mostra commenti meno recenti
I have the following matrix:
[100 200; 150 210; 190 300; 300 400; 410 600; 500 700]
I want to delete the intervals that overlap with previous ones.
The final matrix should be:
[100 200; 300 400; 410 600]
How can I achieve this?
Thanks in advance.
Risposta accettata
Più risposte (1)
the cyclist
il 17 Set 2020
Modificato: the cyclist
il 17 Set 2020
I believe this does what you want:
M = [100 200; 150 210; 190 300; 300 400; 410 600; 500 700];
keepRow = M(2:end,1) >= M(1:end-1,2)
output = M([true;keepRow],:)
There are two nuances:
First, it was unclear whether an exact endpoint match should count as overlap. The above algorithm keeps rows if they are equal.
Second, it was unclear whether this needed to be done sequentially, taking into account if the overlap changes based on a prior remove row. So, for example, what should the output be for this input"
M = [100 200; 150 210; 205 300; 300 400; 410 600; 500 700];
Note that I changed M(3,1) from 190 to 205, so that it overlaps row 2, but does not overlap row 1.
1 Commento
Filipa Cardoso
il 17 Set 2020
Modificato: Filipa Cardoso
il 17 Set 2020
Categorie
Scopri di più su Interpolation in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!