If I have a large matrix with 20 * 13 and each row with random rank from 1 to 13, how can I extend your command to my case? Thank you for help
How to count the number of the rank in each column of a matrix.
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
Wan-Yi Chiu
il 17 Mag 2023
Commentato: Wan-Yi Chiu
il 17 Mag 2023
Load a rank matrix
1 2 3;
2 3 1;
2 1 3;
3 1 2;
1 3 2
How do I count the number of the rank in each column:
The desired output of counting matrix is as follows:
Rank First column Second column Third column
1 2 2 1
2 2 1 2
3 1 2 2
Thank you very much.
7 Commenti
FannoFlow
il 17 Mag 2023
ah it appears the matrix needed to be transposed, thats all.
m = [1 2 3 4 5; 2 5 3 1 4; 2 1 3 5 4; 3 1 2 4 5; 5 4 1 3 2]
u = unique(m);
T = array2table(squeeze(sum(m == permute(u,[3,2,1]), 1)).', RowNames=string(u), VariableNames="Column " + (1:size(m,2)))
Risposta accettata
FannoFlow
il 17 Mag 2023
m = [
1 2 3;
2 3 1;
2 1 3;
3 1 2;
1 3 2]
c = squeeze(sum(m == permute(1:3,[3,1,2]), 1))
0 Commenti
Più risposte (0)
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!