```Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: "Unique" row comparison with duplicate row counter
Date: Fri, 10 Sep 2010 01:01:23 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 17
Message-ID: <i6c013\$7j\$1@fred.mathworks.com>
References: <i6bmgo\$o8e\$1@fred.mathworks.com> <i6bu1a\$mlr\$1@fred.mathworks.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1284080483 243 172.30.248.35 (10 Sep 2010 01:01:23 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 10 Sep 2010 01:01:23 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:668976

"Roger Stafford" <ellieandrogerxyzzy@mindspring.com.invalid> wrote in message <i6bu1a\$mlr\$1@fred.mathworks.com>...
>   Since we have your assurance that A is already in sorted order (presumably in its first two columns,) it would perhaps be a waste of cpu time to sort it again with the unique function.  Try this:
>
>  f = find([true;diff(A(:,1))~=0|diff(A(:,2))~=0;true]);
>  p = f(1:end-1);
>  B = A(p,:);
>  B(:,3) = B(:,3)+f(2:end)-p-1;
>
> Roger Stafford
- - - - - - - - -
I could have eliminated one line of code by writing:

f = find([true;diff(A(:,1))~=0|diff(A(:,2))~=0;true]);
B = A(f(1:end-1),:);
B(:,3) = B(:,3)+diff(f)-1;

Roger Stafford
```