help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: count and sum element negative in array


From: Kai Torben Ohlhus
Subject: Re: count and sum element negative in array
Date: Thu, 20 Sep 2018 10:29:01 +0200

On Thu, Sep 20, 2018 at 10:15 AM shivax <address@hidden> wrote:
example:

a=[-3,4,5,-8,-9]

i want to sum element negative :

3 + 8+  9 =20

it's possible to do it with a function?


In Octave you can make use of logical indexing:

   -sum (a(a<0))

HTH,
Kai 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]