How to pick all elements from a set that satisfy a certain condition?
조회 수: 3 (최근 30일)
이전 댓글 표시
Let's say I have a set of numbers A=-5,-4,-3,-2,-1,0,1,2,3,4,5
and I want to pick those pairs that give a sum of 1. For example, -2 and 3 is one possible pair, but how do we display all such pairs?
Any help will be much appreciated.
댓글 수: 0
채택된 답변
Fangjun Jiang
2024년 7월 9일
편집: Fangjun Jiang
2024년 7월 9일
A=[-5,-4,-3,-2,-1,0,1,2,3,4,5];
index=(A+A')==1;
[I,J]=find(index);
A([I,J])
댓글 수: 0
추가 답변 (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!