Path: news.mathworks.com!newsfeed-00.mathworks.com!kanaga.switch.ch!switch.ch!news.belwue.de!news.germany.com!feed.xsnews.nl!border-1.ams.xsnews.nl!sn-xt-ams-06!sn-xt-ams-04!sn-post-ams-02!sn-post-sjc-01!supernews.com!corp.supernews.com!not-for-mail
From: Jean-Marc Gulliet <jeanmarc.gulliet@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: modified unique
Date: Wed, 24 Oct 2007 15:35:24 +0200
Organization: The Open University, Milton Keynes, UK
Message-ID: <13huignbtbjii53@corp.supernews.com>
User-Agent: Thunderbird 2.0.0.6 (Windows/20070728)
MIME-Version: 1.0
References: <1193230486.076915.167300@z24g2000prh.googlegroups.com>
In-Reply-To: <1193230486.076915.167300@z24g2000prh.googlegroups.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Complaints-To: abuse@supernews.com
Lines: 22
Xref: news.mathworks.com comp.soft-sys.matlab:434403



gopla wrote:

>      I have a array A = [ 1 2 3 3 4 5 5 5 6 6 7 8 9] and want output B
> = [1 2 4 7 8 9]
> 
> i.e. select only the unique numbers from the array and discard all
> numbers that get repeated in the original array.
> 
> I have tried with 'unique' and then a for loop which 'find' number of
> occurrence of a element of the output of unique in the original array.
> I want to simplify this and try to remove the for loop.

  One possible way is using *union* (operation on sets).

  >> A = [1 2 3 3 4 5 5 5 6 6 7 8 9];
  >> union(A,A)
  ans =
       1     2     3     4     5     6     7     8     9

  HTH,
  --
  Jean-Marc