calculating combinations of two vectors simultanously?

1 次查看(过去 30 天)
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 个评论
Jan
Jan 2021-9-8
编辑:Jan 2021-9-8
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?

请先登录,再进行评论。

回答(2 个)

Jan
Jan 2021-9-8
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 2021-9-11
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

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by