nchoosek with multiple arrays
6 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Valeria Villegas-Medina
le 25 Août 2020
Modifié(e) : Valeria Villegas-Medina
le 26 Août 2020
Hello,
Is is possible to use nchoosek in such a way that will keep information for more than one column vector? For example, I have a 33x3 matrix and I'd like to find all possible combinations of trios for the first column, then run calculations on the data from the other two columns associated with each member of the trio from the first column.
Thank you so much in advance for your help!
0 commentaires
Réponse acceptée
Stephen23
le 25 Août 2020
Simply generate a matrix of indices:
idx = nchoosek(1:33,3);
and then for each row in that matrix perform your calculations, where M is your matrix:
for k = 1:size(idx,1)
ix = idx(k,:);
v1 = M(ix,1); % column 1
v2 = M(ix,2); % column 2
v3 = M(ix,3); % column 3
... do whatever with those vectors
end
1 commentaire
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Logical dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!