Sort column vectors of a matrix and extract a new vector from a maximal criterion

2 ビュー (過去 30 日間)
I do have a huge nx4 matrix M in which its column vectors are listed according to given categories. All column vectors from the same category have their first 2 row elements the same(below Example shows 5 I-to V distinct categories) . I need to extract another line vector V built only from the maximal values on the fourth row elements of each vector category(shown with asterisc below them *).V has same elements as nr. of categories. I need to extract V vector
M
<----cat I--------> <----cat II--------> <---cat III----> <----cat IV-----> <---cat III---->
1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 _
1 1 1 1 2 2 2 2 4 4 4 1 1 1 2 2 2 _ 2Rows define category vector
1 2 3 4 1 2 3 4 1 2 3 2 3 4 1 2 3
---------------------------------------------------------------------------------------------------------
31 16 15 9 10 8 13 6 16 11 4 9 4 10 6 17 15 Row with maximal criterion to sort
* * * * * Max value of fourth row of each category
M=[1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2;1,1,1,1,2,2,2,2,4,4,4,1,1,1,2,2,2;1,2,3,4,1,2,3,4,1,2,3,2,3,4,1,2,3;31,16,15,9,10,8,13,6,16,11,4,9,4,10,6,17,15];
V=[31,13,16, 10, 17];
  3 件のコメント
Radu Mihail
Radu Mihail 2021 年 8 月 20 日
Thank you very much Stephen! Yes I transposed a fracțion of a Matrix. Thank you for advice
Radu Mihail
Radu Mihail 2021 年 8 月 20 日
Thank you very much Stephen! Yes I transposed a fracțion of a Matrix. Thank you for advice

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

採用された回答

Stephen23
Stephen23 2021 年 8 月 20 日
編集済み: Stephen23 2021 年 8 月 20 日
M = [1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2; 1,1,1,1,2,2,2,2,4,4,4,1,1,1,2,2,2; 1,2,3,4,1,2,3,4,1,2,3,2,3,4,1,2,3; 31,16,15,9,10,8,13,6,16,11,4,9,4,10,6,17,15];
[~,~,X] = unique(M(1:2,:).','rows','stable');
V = accumarray(X(:),M(4,:),[],@max)
V = 5×1
31 13 16 10 17
or
Y = splitapply(@max,M(4,:).',X(:))
Y = 5×1
31 13 16 10 17
Your data would be easier to work with if it were oriented as an Nx4 matrix.

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

製品


リリース

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by