calculating combinations of two vectors simultanously?

1 回表示 (過去 30 日間)
metin yilmaz
metin yilmaz 2021 年 9 月 8 日
回答済み: metin yilmaz 2021 年 9 月 11 日
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 Center および File ExchangeMATLAB についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by