Remove decreasing data in matrix

8 visualizzazioni (ultimi 30 giorni)
Emily Heil
Emily Heil il 18 Nov 2021
Commentato: Emily Heil il 18 Nov 2021
I have a 2 column matrix with several thousand rows. In one column of the matrix, the data cyclicly increases and decreases. I want to remove all rows where the data is decreasing.
For example if my matrix looked like this:
rawdata = [1 2
2 2
3 2
4 2
5 2
4 2
3 2
2 2
1 2
2 2
3 2
4 2
5 2];
I'd want to remove rows 6-9.
Can anyone help?

Risposta accettata

Matt J
Matt J il 18 Nov 2021
Modificato: Matt J il 18 Nov 2021
rawdata = [1 2
2 2
3 2
4 2
5 2
4 2
3 2
2 2
1 2
2 2
3 2
4 2
5 2];
rawdata( [false; diff(rawdata(:,1))<0] , : )=[]
rawdata = 9×2
1 2 2 2 3 2 4 2 5 2 2 2 3 2 4 2 5 2

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by