Rank the entries of a matrix with codes.

2 vues (au cours des 30 derniers jours)
Wan-Yi Chiu
Wan-Yi Chiu le 16 Mai 2023
Load a matrix:
[12 4 6;
7 3 8;
1 6 5;
9 2 5]
How to rank each row relative to columns with codes as:
3 1 2
2 1 3
1 3 2
3 1 2
Thank you very much.

Réponse acceptée

Walter Roberson
Walter Roberson le 16 Mai 2023
A = [12 4 6;
7 3 8;
1 6 5;
9 2 5]
A = 4×3
12 4 6 7 3 8 1 6 5 9 2 5
[~, idx] = sort(A, 2)
idx = 4×3
2 3 1 2 1 3 1 3 2 2 3 1
[~, rank] = sort(idx, 2)
rank = 4×3
3 1 2 2 1 3 1 3 2 3 1 2

Plus de réponses (0)

Catégories

En savoir plus sur Interpolation dans Help Center et File Exchange

Produits


Version

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by