grouping numbers in matrix
Afficher commentaires plus anciens
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! :)
Réponse acceptée
Plus de réponses (1)
Daniel M
le 23 Oct 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)';
Catégories
En savoir plus sur Cell Arrays dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!