Delete duplicate adjacent characters in a string

I have doubts about the function in MATLAB.

I have this, for example:

a=['9' '9' '9' '-' '-' '1' '1' '2' '3' '3' '5' '6' '7' '7' '7' '9' '6' '4' '-' '-' '3']

a =

999--1123356777964--3

And I want to convert this:

9-123567964-3

Remove the neighboring char that repeats, I tried using:

unique(a,'stable')

But this function removes some characters that are not adjacent.

Is there any function that performs this operation?

Thanks.

+4
source share
1 answer
a(logical([1 diff(double(a))]))

: double. diff , . a. a ( , diff , a).

+4

All Articles