Effacer les filtres
Effacer les filtres

calculating combinations of two vectors simultanously?

4 vues (au cours des 30 derniers jours)
metin yilmaz
metin yilmaz le 8 Sep 2021
I am a beginner so would you please explain the easiest, the most straightforward methods to calculate combinations of more than one vector simultanously?
a=[1, 3, 5, 7, 9] and b=[2, 4, 6, 8, 10] I would like to calculate the (a,3) and (b,3) simultanously and the results should be combined. How can I do it instead of doing nchoosek(a,3) and nchoosek(b,3) I would like to do it in less steps, if possible one step.
Thank you.
  1 commentaire
Jan
Jan le 8 Sep 2021
Modifié(e) : Jan le 8 Sep 2021
It is not clear to me, what this means: "calculate the (a,3) and (b,3) simultanously and the results should be combined".
What is the wanted output?

Connectez-vous pour commenter.

Réponses (2)

Jan
Jan le 8 Sep 2021
a = [1, 3, 5, 7, 9];
b = [2, 4, 6, 8, 10];
index = nchoosek(1:numel(a), 3);
a(index)
ans = 10×3
1 3 5 1 3 7 1 3 9 1 5 7 1 5 9 1 7 9 3 5 7 3 5 9 3 7 9 5 7 9
b(index)
ans = 10×3
2 4 6 2 4 8 2 4 10 2 6 8 2 6 10 2 8 10 4 6 8 4 6 10 4 8 10 6 8 10

metin yilmaz
metin yilmaz le 11 Sep 2021
Sorry, for being late. You did the operation for a and for b. Can you do one operation that will calculate both a(index) and b(index) and give them as the result. That is the result will be:
1 3 5
1 3 7
1 3 9
1 5 7
1 5 9
1 7 9
3 5 7
3 5 9
3 7 9
5 7 9
2 4 6
2 4 8
2 4 10
2 6 8
2 6 10
2 8 10
4 6 8
4 6 10
4 8 10
6 8 10

Catégories

En savoir plus sur Matrices and Arrays 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!

Translated by