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

1 visualización (últimos 30 días)
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 comentarios
Radu Mihail
Radu Mihail el 20 de Ag. de 2021
Thank you very much Stephen! Yes I transposed a fracțion of a Matrix. Thank you for advice
Radu Mihail
Radu Mihail el 20 de Ag. de 2021
Thank you very much Stephen! Yes I transposed a fracțion of a Matrix. Thank you for advice

Iniciar sesión para comentar.

Respuesta aceptada

Stephen23
Stephen23 el 20 de Ag. de 2021
Editada: Stephen23 el 20 de Ag. de 2021
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.

Más respuestas (0)

Categorías

Más información sobre Shifting and Sorting Matrices en Help Center y File Exchange.

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by