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 CenterFile Exchange에서 Shifting 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