- If you take your data and do [F,X] = ecdf(A) then this will compute the empirical distribution of A.
- You then just have to match the values in A to those in X which you can do using ismember like this [~,loc] = ismember(X,X2)
- Finally, your quantiles of the values in A will be f(loc)
- You can then sort them into deciles, or whatever you want at that point by rounding to the appropriate value.
Matlab - Sort into deciles each column
조회 수: 7 (최근 30일)
이전 댓글 표시
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
댓글 수: 0
채택된 답변
jgg
2015년 12월 4일
I think a way to do this is to use the ecdf command (<http://www.mathworks.com/help/stats/ecdf.html>)
I also found this code http://www.mathworks.com/matlabcentral/fileexchange/41131-inverse-percentiles-of-a-sample which might be helpful.
댓글 수: 0
추가 답변 (1개)
René Wijnen
2021년 7월 30일
편집: René Wijnen
2021년 7월 30일
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
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Logical에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!