How to find which postions in a vector has negative values and output them?

3 views (last 30 days)
i have a vector and need to find the postions which has negative values

Accepted Answer

Birdman
Birdman on 17 Feb 2018
Edited: Birdman on 17 Feb 2018
Say your vector is A:
idx=find(A<0)
ANeg=A(idx)

More Answers (1)

Stephen23
Stephen23 on 17 Feb 2018
find is not required, logical indexing is simpler and more efficient:
B = A(A<0)

Categories

Find more on Startup and Shutdown in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!