Remove duplicate values, but keep the initial

1 vue (au cours des 30 derniers jours)
James Boyle
James Boyle le 28 Fév 2017
Commenté : James Boyle le 1 Mar 2017
For example, i have
x = [0 0 0 1 1 0 0 0 1 0 1 0]
I want the index of the first zero or one, but not the duplicates.
So the vector should become:
0 1 0 1 0 1 0
Where the indices would be '1 4 6 9 10 11 12'
Thanks

Réponse acceptée

Stephen23
Stephen23 le 28 Fév 2017
Modifié(e) : Stephen23 le 28 Fév 2017
>> x = [0,0,0,1,1,0,0,0,1,0,1,0];
>> idx = [1,1+find(diff(x)~=0)]
idx =
1 4 6 9 10 11 12
>> vec = x(idx)
vec =
0 1 0 1 0 1 0

Plus de réponses (1)

Jan
Jan le 28 Fév 2017
x = [0 0 0 1 1 0 0 0 1 0 1 0]
[B, N, Index] = RunLength(x)
Then B contains the unique values and Index the indices.

Catégories

En savoir plus sur Elementary Math dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by