How to remove repeating entries from a vector?

2 Ansichten (letzte 30 Tage)
L'O.G. am 17 Apr. 2023
Kommentiert: Image Analyst am 17 Apr. 2023
How do you remove repeating entries in a vector?
For example: A = [1 1 1 0 0 1 1 1 1 0 0 0 0 0] should return B = [ 1 0 1 0].
The unique function does not do this from what I can tell. For the above example, it would return [0 1], which is not what I want.
1 Kommentar-1 ältere Kommentare anzeigen-1 ältere Kommentare ausblenden
Image Analyst am 17 Apr. 2023
Are the values always 1s and 0s? Or could you have something like [9,9,9,4,4,6,6,6,1,1,0,2,2]? If the latter would the result be [9,4,6,1,0,2]? What's the use case? Why do you need it? Is it your homework?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Matt J am 17 Apr. 2023
Bearbeitet: Matt J am 17 Apr. 2023
A = [1 1 1 0 0 1 1 1 1 0 0 0 0 0];
starts=groupLims(A);
B = A(starts)
B =
1 0 1 0
0 Kommentare-2 ältere Kommentare anzeigen-2 ältere Kommentare ausblenden

Melden Sie sich an, um zu kommentieren.

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by