Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!e8g2000yqo.googlegroups.com!not-for-mail
From: arun <aragorn168b@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: unique() Help
Date: Mon, 7 Sep 2009 09:16:40 -0700 (PDT)
Organization: http://groups.google.com
Lines: 18
Message-ID: <813a9440-f582-4533-b5c4-025dde6473b8@e8g2000yqo.googlegroups.com>
References: <h83aia$5dv$1@fred.mathworks.com>
NNTP-Posting-Host: 134.2.162.201
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
X-Trace: posting.google.com 1252340201 27037 127.0.0.1 (7 Sep 2009 16:16:41 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Mon, 7 Sep 2009 16:16:41 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: e8g2000yqo.googlegroups.com; posting-host=134.2.162.201; 
	posting-account=fyqXpgoAAABqt-0BifyaNxmZhzggFACu
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; 
	rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:568788


On Sep 7, 5:58 pm, "Husam Aldahiyat" <numand...@gmail.com> wrote:
> Hello,
> I need a function that outputs the unique elements of each column of my desired matrix.
> I can use
> sum(~~diff(sort(A)))+1
> to get the number of unique elements in each column of a matrix A,
> but can't I produce a cell or zero padded matrix for what the unique elements are?
> I used a loop and it takes 99% of my calculation time and is killing me!
>
> Help!!!

given matrix y (with n columns),
u = arrayfun(@(x) unique(y(:,x)), 1:size(y,2), 'uni', false);
will give a 1*n cell array with each element holding the unique
elements of the column.
best, arun.