How to delete adjacent values
4 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Nao
am 25 Okt. 2022
Kommentiert: Nao
am 27 Okt. 2022
Hello
I have a vector of 1400x1 with several adjacent values (values with a difference of less than 1).
For example, my data looks like
A = [1 5 6 7 8 9 10 11 12 20 21 22 23]'
I'd like to delete the row that is adjacent to the previous one, so my expected outcome will be [1; 5; 20]
Any ideas on how to do this? I appreciate your help!
0 Kommentare
Akzeptierte Antwort
Davide Masiello
am 25 Okt. 2022
A = [1 5 6 7 8 9 10 11 12 20 21 22 23];
A([false,diff(A) == 1]) = []
5 Kommentare
Image Analyst
am 26 Okt. 2022
But since you said "a difference of less than 1" you'd want <1 instead of == 1
A([false;diff(A) < 1]) = []
Of course then your expected outcome is not right. Maybe you mean "a difference of 1 or less" in which case it would be
A([false;diff(A) <= 1]) = []
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Matrix Indexing finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!