help-octave
[Top][All Lists]
Advanced

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

Re: how do I vectorize this?


From: Etienne Grossmann
Subject: Re: how do I vectorize this?
Date: Fri, 14 Apr 2006 10:48:16 -0400
User-agent: Mutt/1.4.2.1i

  Hi,

sthing like this?

octave:2> help loop_add
loop_add is the dynamically-linked function from the file
/homeætienne/progøctave/miscøctave-3Dvision/misc/loop_add.oct

 -- Loadable Function: B = loop_add (A, INDICES, WHAT)
     This function is equivalent to, but is quicker than :

     B=A; for J=1:rows(INDICES(:)), B(INDICES(J)) += WHAT(J); end

     WHAT is optional and is 1 by default.

     If  WHAT has less elements than INDICES, values of WHAT are
     wrapped. I.e. WHAT(1 + rem(J-1,rows(WHAT(:))) is used instead of
     WHAT(J).

octave:11> loop_add (zeros(1,10),(1:3).^2)
ans =

  1  0  0  1  0  0  0  0  1  0

octave:12> loop_add (zeros(1,10),(1:3).^2,2*ones(1,3))
ans =

  2  0  0  2  0  0  0  0  2  0

octave:13> loop_add (zeros(1,10),(1:3).^2,[2 3])
ans =

  2  0  0  3  0  0  0  0  2  0

octave:14> loop_add (zeros(1,10),(1:4).^2,[2 3])
error: loop_add: Can't add to a(16) because a has only 10 elements.

If yes, it's in the attachment.

  Hth,

  Etienne

On Fri, Apr 14, 2006 at 12:56:43PM +0200, Miroslaw Kwasniak wrote:
# On Fri, Apr 14, 2006 at 10:52:18AM +0200, Claudio Belotti wrote:
# > 
# > Hi Brendan,
# > thank you for your reply. This is not really what I need as my data are 
ungridded I don't think it would be convinient to organize them in a matrix.
# 
# Look in archives for an idea  in thread "for i=1:bignum, x(a(i)) += y(i);
# end" from 2005.
# 
# PS
# 
# I think octave archives are incomplete, I'm  sure that were more then two
# posts in this thread :(
# 
# 
# 
# -------------------------------------------------------------
# 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
# -------------------------------------------------------------

-- 
Etienne Grossmann ------ http://www.cs.uky.edu/~etienne

Attachment: loop_add.cc
Description: Text document


reply via email to

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