help-octave
[Top][All Lists]
Advanced

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

Re: subsums


From: Dmitri A. Sergatskov
Subject: Re: subsums
Date: Sun, 06 Feb 2005 10:01:48 -0700
User-agent: Mozilla Thunderbird 0.9 (X11/20041127)

Gorazd Brumen wrote:
Hi,

How do you form a vector of subsums of a certain vector without the for loop?
Example:
Let x = [1 2 3 4 5 6 7 8 9 10]
I want to get a vector that would have as entries
sum([1 2 3 4 5]) and sum ([6 7 8 9 10])?


octave:1> x = [1 2 3 4 5 6 7 8 9 10]
x =

  1   2   3   4   5   6   7   8   9  10

octave:2> y=reshape(x,5,2)
y =

  1   6
  2   7
  3   8
  4   9
  5  10

octave:3> z=sum(y)
z =

 15  40


Thanks,
g.



Regards,

Dmitri.
--



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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