Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: help with unique function
Date: Wed, 5 May 2010 10:38:04 +0000 (UTC)
Organization: The MathWorks Inc
Lines: 28
Message-ID: <hrrhqc$qad$1@fred.mathworks.com>
References: <hrrgbg$mk0$1@fred.mathworks.com>
Reply-To: <HIDDEN>
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 1273055884 26957 172.30.248.35 (5 May 2010 10:38:04 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 5 May 2010 10:38:04 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1597503
Xref: news.mathworks.com comp.soft-sys.matlab:632700

"Fraser Dickson" <fraser.dickson@gmail.com> wrote in message <hrrgbg$mk0$1@fred.mathworks.com>...
> Hi im trying to use the uniqie function to get rid of duplicate entries within my array but im having some trouble with it.
> 
> I have a 2d array always with 2 cols
> 
> I want to only perofrm the unique function to col2 but always delete the corresponding value in that row form col 1
> 
> eg.
> 
> a = [ 2,23 ; 3,25; 4,23; 5,25; 6,26 ;7,23 ; 8,27 ; 9,28 ; 10,29]
> 
> i want b to equal what i have mentioned  above which should hopefully give me
> 
> b = [2,23 ; 3,25 ; 6,26 ; 8,27 ; 9,28 ; 10,29]
> 
> a = unique(b) does not do this ?
> 
> Can someone help me out ?

Hi, One way

[elements,I,J] = unique(a(:,2),'first');
B = zeros(size(a));
B(I,:)=a(I,:);
EmptyInd = setdiff(1:size(a,1),I);
B(EmptyInd,:)=[];

Wayne