negative number in vector

12 views (last 30 days)
bsta
bsta on 14 Feb 2019
Answered: madhan ravi on 14 Feb 2019
say I have a vector v=[1 2 5 6 -8 5 2 7]
and I to create a new vector that has all the elements until the negative number shows up
such as c=[1 2 5 6]
how would you do this without using a while loop

Accepted Answer

madhan ravi
madhan ravi on 14 Feb 2019
c=v(1:find(v<0,1,'first')-1)

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Products


Release

R2017a

Community Treasure Hunt

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

Start Hunting!