Borrar filtros
Borrar filtros

unique function but with repeated groups

1 visualización (últimos 30 días)
Haneya Qureshi
Haneya Qureshi el 24 de Abr. de 2021
Respondida: Haneya Qureshi el 24 de Abr. de 2021
I have= [1 1 1 5 5 5 1 1]
I want first indices of each repeat values: [1 4 7]
i.e., the first group of repeated 1's start at index 1, the second group of repeated 5's start at index 4 and the third group of repeated 1s start at index 7
I am trying unique function, but it misses out the last group of 1s.
[~,ic,~]=unique([1 1 1 5 5 5 1 1], 'stable')
gives me [1 4] and not [1 4 7]

Respuesta aceptada

Haneya Qureshi
Haneya Qureshi el 24 de Abr. de 2021
Figured it out!
G= [1 1 1 5 5 5 1 1]
temp = [0, diff(G(:)')==0,0];
index = strfind(temp,[1 0]);

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by