negative number in vector

15 vues (au cours des 30 derniers jours)
bsta
bsta le 14 Fév 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

Réponse acceptée

madhan ravi
madhan ravi le 14 Fév 2019
c=v(1:find(v<0,1,'first')-1)

Plus de réponses (0)

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Produits


Version

R2017a

Community Treasure Hunt

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

Start Hunting!

Translated by