How to select real positive number ?

24 views (last 30 days)
How do I pick up only real positive numbers from array or matrix which has all types of numbers such as positive ,negative real numbers and complex numbers?
I tried A(A>0) but it returns positive number but also complex numbers whose real part is positive.
For example, A=[1,-3,4,1+2i,5-3i,-9-i,9+3i];
B=A(A>0)
then I got
B=[1,4,1+2i,5-3i,9+3i]
But how do I get B=[1,4]?
Thanks

Accepted Answer

Roger Stafford
Roger Stafford on 9 Oct 2013
B=A(real(A)>0&imag(A)==0);

More Answers (0)

Categories

Find more on Resizing and Reshaping Matrices in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!