All possible pairs in a vector

29 ビュー (過去 30 日間)
Antonis Asiminas
Antonis Asiminas 2018 年 4 月 15 日
コメント済み: Star Strider 2018 年 4 月 15 日
Hi, and thank you in advance for taking the time to read this. Is there a quick way to get all possible pairs from a vector? For example A=[1 2 3 4 5]; [1 2], [1 3], [1 4], [1 5], [2 3], [2 4], [2 5], [3 4], [3 5], [4 5]. I think I can get that with 2 for loops but I would like to know if there's a know faction for that.
Thank you

採用された回答

Star Strider
Star Strider 2018 年 4 月 15 日
Try this:
A = [1 2 3 4 5];
Out = nchoosek(A, 2)
Out =
1 2
1 3
1 4
1 5
2 3
2 4
2 5
3 4
3 5
4 5
  2 件のコメント
Antonis Asiminas
Antonis Asiminas 2018 年 4 月 15 日
Works like a charm! Thank you!
Star Strider
Star Strider 2018 年 4 月 15 日
As always, my pleasure!

サインインしてコメントする。

その他の回答 (1 件)

David Fletcher
David Fletcher 2018 年 4 月 15 日
nchoosek(A,2)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by