Recoding unique numbers to another number
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Cside
el 28 de Dic. de 2020
Respondida: Walter Roberson
el 28 de Dic. de 2020
Hi I have this array of numbers [5 5 6 6 6 11 11 ]and would like to convert every unique number from 1 to n. For example, if there are 10 unique numbers, I would like to relabel them from 1 to 10, with the same number coded the same for eg [1 1 2 2 2 3 3]
The actual array is attached here. How may I code for this? Thanks so much!
0 comentarios
Respuesta aceptada
Stephen23
el 28 de Dic. de 2020
The simple and efficient MATLAB solution:
X = [5,5,6,6,6,11,11];
[~,~,Z] = unique(X,'stable')
0 comentarios
Más respuestas (2)
KALYAN ACHARJYA
el 28 de Dic. de 2020
Editada: KALYAN ACHARJYA
el 28 de Dic. de 2020
data=[5 5 6 6 6 11 11];
counts=histc(data,unique(data));
data_result=repelem(1:length(unique(data)),counts)
Results:
data_result =
1 1 2 2 2 3 3
0 comentarios
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!