Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: how to sum elements with identical subscript
Date: Sat, 29 Nov 2008 04:56:01 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 20
Message-ID: <ggqi11$4jn$1@fred.mathworks.com>
References: <ggq9j1$ssm$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1227934561 4727 172.30.248.35 (29 Nov 2008 04:56:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Sat, 29 Nov 2008 04:56:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:503752


"vagrom Jiang" <vagrom@mytum.de> wrote in message <ggq9j1$ssm$1@fred.mathworks.com>...
> here is an example,  A is N*2 matrix,
> A = [2  20;
>         5 10;
>         5 30;
>         7 10;
>         .......];
> expected result is A= [2  20;
>                                 5  40;
>                                 7  10;
>                                 .........];
> how to  solve this problem without any  Loop to implement, since N could be very large, e.g 10e6.

  Or if you want to do it from scratch you can do it this way:

 [t,m,n] = unique(A(:,1));
 A = [t,accumarray(n,A(:,2))];
 
Roger Stafford