How to pick all elements from a set that satisfy a certain condition?
2 ビュー (過去 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!