Matlab: delete duplicate consecutive values in an array

Viewed 275

I have this array

Y=[618 1 631 618 631 618 631 631 631 618 631 627 631 631]

and I want to trasform it in:

[618 1 631 618 631 618 631 618 631 627 631]

I have used this code

[~,index] = unique(Y,'first');       
Y(sort(index))

but the answer is this, that it's different from the result that I want. ans = 618 1 631 627

Can you help me?

1 Answers
Related