How to count the number of the rank in each column of a matrix.

1 回表示 (過去 30 日間)
Wan-Yi Chiu
Wan-Yi Chiu 2023 年 5 月 17 日
コメント済み: Wan-Yi Chiu 2023 年 5 月 17 日
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 件のコメント
FannoFlow
FannoFlow 2023 年 5 月 17 日
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]
m = 5×5
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)))
T = 5×5 table
Column 1 Column 2 Column 3 Column 4 Column 5 ________ ________ ________ ________ ________ 1 1 2 1 1 0 2 2 1 1 0 1 3 1 0 3 1 0 4 0 1 0 2 2 5 1 1 0 1 2
Wan-Yi Chiu
Wan-Yi Chiu 2023 年 5 月 17 日
It works. Thank you very much.

サインインしてコメントする。

採用された回答

FannoFlow
FannoFlow 2023 年 5 月 17 日
m = [
1 2 3;
2 3 1;
2 1 3;
3 1 2;
1 3 2]
m = 5×3
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))
c = 3×3
2 2 1 2 1 2 1 2 2

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeInterpolation についてさらに検索

製品


リリース

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by