Matlab - Sort into deciles each column
Mostrar comentarios más antiguos
Suppose I have a matrix A [m x 1], where m is not necessarily even. I to create a matrix B also [m x 1] which tells me the decile of the elements in A (i.e. matrix B has numbers from 1 to 10).
I know I can use the function sort(A) to get the position of the elements in A and from there I can manually get deciles. Is there another way of doing it?
I think one possibility would be B = ceil(10 * tiedrank(A) / length(A) . What do you think? Are there any issues with this?
Also, more generally, if I have a matrix A [m x n] and I want to create a matrix B also [m x n], in which each column of B should have the decile of the corresponding column in A , is there a way of doing it without a for loop through the columns?
Hope the problem at hand is clear. So far I have been doing it using the sort function and then manually assigning the deciles, but it is very inefficient.
Thank you
Respuesta aceptada
Más respuestas (1)
René Wijnen
el 30 de Jul. de 2021
Editada: René Wijnen
el 30 de Jul. de 2021
0 votos
I would use the following to split a vector X into deciles:
X_dec = discretize(X,quantile(X,[0:10]/10))
Works as well for each column of an array X
Categorías
Más información sobre Shifting and Sorting Matrices en Centro de ayuda y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!