How do you get all pairs without double counting?
조회 수: 3 (최근 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!