How do I remove paired data in a matrix?

Let's say I have a matrix,
A =
1 0
-2 -9
3 7
4 -3
-9 10
5 6
How would I be able to filter it out so that both columns are positive numbers? If either column is negative, then you should delete the whole row. The output should be
A =
1 0
3 7
5 6
I am stuck and don't know the direction to go towards. How should I do this? Any help will be appreciated. Thank you!

 采纳的回答

dpb
dpb 2018-9-3
编辑:dpb 2018-9-3
A(any(A<0,2),:)=[];
Or, vice versa, keep the wanted--
A=A(all(A>=0,2),:); % keeps 0 as +ive
Look up logical indexing

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 MATLAB 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by