help-octave
[Top][All Lists]
Advanced

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

Re: Summing elements in an array


From: Andy Buckle
Subject: Re: Summing elements in an array
Date: Thu, 15 Jul 2010 10:58:00 +0100

> I am wanting to sum the first 1000 elements in a matrix I have defined.

How many dimensions? This might help.

sum(m(1:1000))

> Initially I want to perform it on one column, but then move to performing

Assuming 2D...

sum(m(1:1000,column_index))

> the calculation over all 20 columns. Is there a way to do this as I am

sum(m(1:1000,1:20))

> having great difficulty using for loops for this.
>
> Another question is if three nested for loops for analyzing a 210000 element
> array is going to be slow...

Not using loops will be faster. We can probably be more helpful if you
provide more info. Same goes for the above sum and indexing stuff.

Andy


reply via email to

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