Path: news.mathworks.com!not-for-mail
From: "Ori " <john.doe.nospam@mathworks.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: accessing the same elements repeatedly in a vectorized fashion?
Date: Thu, 2 Aug 2007 02:29:29 +0000 (UTC)
Organization: Ori Weitz (ID: 1-1VBMYR)
Lines: 28
Message-ID: <f8rfi9$4sa$1@fred.mathworks.com>
References: <f8r2uh$oib$1@fred.mathworks.com> <f8r3o3$7qj$1@fred.mathworks.com>
Reply-To: "Ori " <john.doe.nospam@mathworks.com>
NNTP-Posting-Host: webapp-01-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1186021769 5002 172.30.248.36 (2 Aug 2007 02:29:29 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 2 Aug 2007 02:29:29 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 496412
Xref: news.mathworks.com comp.soft-sys.matlab:422130


Thanks!

"Naor Movshovitz" <lazy_n@yahoo.com> wrote in message <f8r3o3$7qj$1@fred.mathworks.com>...
> The function accumarray is what you need.
> 
> 
> "Ori " <john.doe.nospam@mathworks.com> wrote in message <f8r2uh$oib$1@fred.mathworks.com>...
> > Hello, 
> > 
> > I would like to vectorize the following loop.
> > 
> > for i = 1:length(c)
> >   a(b(i)) = a(b(i)) + c(i)
> > end
> > 
> > However, a simple 
> > 
> >  a(b) = a(b) + c 
> > 
> > will not work as 'b' is not one-to-one. Matlab will only add one (the last, I think) value of 'c' to each corresponding 'a' element. I would like to add all the corresponding values in 'c', just like in the loop.
> > 
> > Any ideas?
> > 
> > Please note that in my particular case, the multiplicity of 'b' is not fixed or constant. That is, each element of 'a' is accessed a different number of times (between 3 to, say, 8 times) by 'b'. 
> > 
> > Thanks.
>