calculating combinations of two vectors simultanously?

1 visualización (últimos 30 días)
metin yilmaz
metin yilmaz el 8 de Sept. de 2021
Respondida: metin yilmaz el 11 de Sept. de 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 comentario
Jan
Jan el 8 de Sept. de 2021
Editada: Jan el 8 de Sept. de 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?

Iniciar sesión para comentar.

Respuestas (2)

Jan
Jan el 8 de Sept. de 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 el 11 de Sept. de 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

Categorías

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

Community Treasure Hunt

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

Start Hunting!

Translated by