help-octave
[Top][All Lists]
Advanced

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

Reducing for loop


From: Dr.-Ing. Dieter Jurzitza
Subject: Reducing for loop
Date: Wed, 25 Mar 2015 21:09:44 +0100
User-agent: KMail/1.13.6 (Linux/3.11.10-25-desktop; KDE/4.11.5; x86_64; ; )

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

In order to get this vectorized I tried to write something like

B(1)=A(1) # IMHO no way around ...

# apparently does not work ...
for i=2:n
   B=A(i)+B(i-1);
endfor

What am I doing wrong here? Apparently using the indexed left - side array on 
the right side is causing trouble ... Many thanks for any explanation in 
advance,
take care




Dieter Jurzitza


-- 
-----------------------------------------------------------

                               |
                                \
                 /\_/\           |
                | ~x~ |/-----\   /
                 \   /-       \_/
  ^^__   _        /  _  ____   /
 <°°__ \- \_/     |  |/    |  |
  ||  ||         _| _|    _| _|

if you really want to see the pictures above - use some font
with constant spacing like courier! :-)
-----------------------------------------------------------



reply via email to

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