Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Summing content of one matrix based on another
Date: Thu, 7 Jul 2011 22:30:25 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 14
Message-ID: <iv5c20$od7$1@newscl01ah.mathworks.com>
References: <iv4c7e$gv5$1@newscl01ah.mathworks.com> <iv50lp$ml3$1@newscl01ah.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-01-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1310077825 24999 172.30.248.46 (7 Jul 2011 22:30:25 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 7 Jul 2011 22:30:25 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:735457

"Roger Stafford" wrote in message <iv50lp$ml3$1@newscl01ah.mathworks.com>...
> "Ulrik Nash" <uwn@sam.sdu.dk> wrote in message <iv4c7e$gv5$1@newscl01ah.mathworks.com>...
> > The answer in this case is
> > 228	256	238	240	223	229
>  [m,n[ = size(A);
>  C = sum(reshape(A(sub2ind([m,n],repmat((1:m).',n,1),B(:))),m,n),1);
- - - - - - - - - - 
  My result for your example agrees only with the first and the last elements of C.  The middle four are different.  Did you make a mistake in addition or do I not understand your problem?

  The first line is supposed to be:

 [m,n] = size(A);

Roger Stafford