Clear Filters
Clear Filters

How to delete row between a certain value in one column and a certain event in the second column?

2 views (last 30 days)
Hi all,
I have a matrix with two columns and millions of rows. The first column is time and the second one is events consisted of 0 or 1 only.
As an example, the matrix is: [560 0 ; 570 0; 580 0; 590 0; 600 0; 610 0; 620 0; 630 0; 640 1; 650 1; 660 0; 670 0; 680 0; 690 1; 700 0]
I would like to delete all the rows between 600s and the first time the event is 1, knowing that the first "1" event can never be < 600 s.
Thanks a lot for your help!

Accepted Answer

Torsten
Torsten on 30 Mar 2022
Edited: Torsten on 30 Mar 2022
A= [560 0 ; 570 0; 580 0; 590 0; 600 0; 610 0; 620 0; 630 0; 640 1; 650 1; 660 0; 670 0; 680 0; 690 1; 700 0];
idx = find(A(:,1) >= 600);
jdx = find(A(idx,2) == 1,1,'first');
A(idx(1):idx(jdx)-1,:) = []

More Answers (0)

Community Treasure Hunt

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

Start Hunting!