필터 지우기
필터 지우기

Ranking values - sorting into descending order

조회 수: 3 (최근 30일)
david crowley
david crowley 2021년 7월 24일
답변: Max Heiken 2021년 7월 24일
I have a that for each row (i) ranks the column values. However, it ranks them in the ascending order. I require it to be ranked in descending order. Can anyone help with modifying the below code block to descending order?
for i = 1:height(d)
[temp, ranked] = ismember(X(i,:),unique(X(i,:)));
rnkR1List(i,:) = ranked;
end

채택된 답변

Max Heiken
Max Heiken 2021년 7월 24일
If you do not expect there to be duplicates, I too recommend to use sort instead.
[~, rnkR1List] = sort(X, 2, 'descend');
If you absolutely need identical values to have the same ranks, then you could extend your own code by just inverting the ranks:
for i = 1:height(d)
[temp, ranked] = ismember(X(i,:),unique(X(i,:)));
rnkR1List(i,:) = ranked;
end
max(rnkR1List, [], 2) - rnkR1List + 1;

추가 답변 (1개)

Yazan
Yazan 2021년 7월 24일
Just use the Matlab function sort without any looping. See an example below.
X = randn(10, 10);
Xranked = sort(X, 2, 'descend');

카테고리

Help CenterFile Exchange에서 Matrices and Arrays에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by