I have sequence
a=[17 56 42 12 12 99 102 45 76 76 41 99 12 45 56 17 76 86 125 160 36]
I want to do that give numbering to sequence starting from 1 i.e.minimum value is 12 so give it 1 then next value greater than 12 is 17 so give it 2 likewise so
a = [17 56 42 12 12 99 102 45 76 76 41 99 12 45 56 17 76 86 125 160 36]
a1 = [2 7 5 1 1 10 11 6 8 8 4 10 1 5 7 2 8 9 12 13 3]
how to do this.

 Respuesta aceptada

Image Analyst
Image Analyst el 30 de Dic. de 2016

1 voto

Here's one semi-vectorized way:
a=[17 56 42 12 12 99 102 45 76 76 41 99 12 45 56 17 76 86 125 160 36]
uniquea = unique(a)
labels = 1 : length(uniquea)
for k = 1 : length(a)
index = find(a(k) == uniquea);
a1(k) = labels(index);
end

3 comentarios

Jay Hanuman
Jay Hanuman el 30 de Dic. de 2016
but i don't want to disturb original sequence so in original sequence way numbering should be display. in above solution original sequence displays in increasing order numbers.
Image Analyst
Image Analyst el 30 de Dic. de 2016
My code gives
a1 =
Columns 1 through 17
2 7 5 1 1 10 11 6 8 8 4 10 1 6 7 2 8
Columns 18 through 21
9 12 13 3
Tell me which elements are not in the same order as the a1 you gave, which is a1 = [2 7 5 1 1 10 11 6 8 8 4 10 1 5 7 2 8 9 12 13 3]
I'm just not seeing any difference between my output and yours so I need you to point it out to me. Which indexes are bad?
Jay Hanuman
Jay Hanuman el 30 de Dic. de 2016
Editada: Jay Hanuman el 30 de Dic. de 2016
sorry, it gives right result, I didn't saw clearly, Thank You.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Centro de ayuda y File Exchange.

Preguntada:

el 30 de Dic. de 2016

Editada:

el 30 de Dic. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by