How do you get all pairs without double counting?
1 回表示 (過去 30 日間)
古いコメントを表示
Given, say, 10 numbers, how do you get all possible pairs between the numbers without double counting? Order doesn't matter, so 1-3 is the same as 3-1. How would you do this with for loops vs. vectorized? Is there a difference in performance between the two?
0 件のコメント
回答 (1 件)
Voss
2022 年 7 月 16 日
Here's one way:
ten_numbers = 1:10;
all_pairs = nchoosek(ten_numbers,2);
disp(all_pairs);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Get Started with MATLAB についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!