grouping numbers in matrix
Mostrar comentarios más antiguos
Hi, I have 2 matrices
A = [ 1, 2, 3, 2, 2, 3, 3, 1, 1]
B = [34, 20, 23, 31, 30, 33, 44, 22, 28]
and would like to group them according to their numbers in A. The answer should be a 3 x 3 matrix (A corresponds to column number).
Thank you! :)
Respuesta aceptada
Más respuestas (1)
Daniel M
el 23 de Oct. de 2019
This is not a generalized solution, and assumes that there will always be three entries of each number (1, 2, 3) in A.
[~,sortOrder] = sort(A);
B2 = reshape(B(sortOrder),3,3)';
Categorías
Más información sobre Cell Arrays en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!