|
From: | Przemek Klosowski |
Subject: | Re: Reducing for loop |
Date: | Wed, 25 Mar 2015 16:21:49 -0400 |
User-agent: | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.5.0 |
On 03/25/2015 04:09 PM, Dr.-Ing. Dieter
Jurzitza wrote:
If you unroll that, I believe that you'd get:Dear listmembers, I am using a for loop as follows. I have an array, say A, containing numelem elements. Now I want to fill array B with elements as follows: B(1)=A(1) for i=2:numelem B(i)=B(i-1)+A(i); endfor B(1) = A(1) B(2) = B(1) + A(2) = A(1) + A(2) B(3) = B(2) + A(3) = A(1) + A(2) + A(3) ... B(N) = .... = A(1) + A(2) +...+A(N) so, simply, B=cumsum(A) |
[Prev in Thread] | Current Thread | [Next in Thread] |