How to find 'numbers' of unique variable in matrix. How many quantity of variables.
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Triveni
el 30 de Oct. de 2015
Respondida: Konstantinos Sofos
el 30 de Oct. de 2015
x=[2 5 2 52 5 25 2 5 2 22 5 2 5 52 5 55 4 5 5 2 5 5 25 2 5 2 54 5 54 5 2 5 5 5 5 5 5 5 25 2 255 2 5 5 2 55 2 5 5 2 5 5 2 255 2 52 5 2 5 ];
unique(x)
ans =
Columns 1 through 6
2 4 5 22 25 52
Columns 7 through 9
54 55 255
How to find numbers using command. How many numbers of unique variable.
0 comentarios
Respuesta aceptada
Konstantinos Sofos
el 30 de Oct. de 2015
Hi,
To reformulate your question (as I understood it) you would like to be able to return the count of occurrences of each element in a vector. There are multiple ways to do this. One solution would be by using hist and unique functions
x=[2 5 2 52 5 25 2 5 2 22 5 2 5 52 5 55 4 5 5 2 5 5 25 2 5 2 54 5 54 5 2 5 5 5 5 5 5 5 25 2 255 2 5 5 2 55 2 5 5 2 5 5 2 255 2 52 5 2 5 ];
>> [a,b]=hist(x,unique(x))
a =
17 1 28 1 3 3 2 2 2
b =
2 4 5 22 25 52 54 55 255
where a(i) is the (count) of b(i).
0 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Problem-Based Optimization Setup en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!