calculating combinations of two vectors simultanously?

1 view (last 30 days)
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 Comment
Jan
Jan on 8 Sep 2021
Edited: Jan on 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?

Sign in to comment.

Answers (2)

Jan
Jan on 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 on 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

Categories

Find more on MATLAB in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!