Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Counting Genotypes from Alleles
Date: Tue, 29 Mar 2011 19:27:03 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 21
Message-ID: <imtbq7$cmv$1@fred.mathworks.com>
References: <imt4a8$nh$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: www-00-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1301426823 13023 172.30.248.45 (29 Mar 2011 19:27:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 29 Mar 2011 19:27:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: news.mathworks.com comp.soft-sys.matlab:718895

"Amanda " <ahulse@tamu.edu> wrote in message <imt4a8$nh$1@fred.mathworks.com>...
> I am trying to count the number of times a combination of alleles occur in a single matrix. Does anyone know how to write a correct function for this? I have looked into the 'unique' command however it does not seem to give me the correct number.
> 
> For example for the following vector, how many times does A occur in column 1 along with A in column 2. 
> vec=[A A
> A A
> A A
> A a
> A A
> a a]
> Where the answer would be 4. 
> Thank you!
- - - - - - - - - - -
  If you want a list of all unique pairs occurring in 'vec' along with their corresponding counts, you can use the 'unique' function with the 'rows' option specified.

 [u,~,n] = unique(vec,'rows');
 list = [u,diff(find([true;diff(sort(n))>0;true]))];

Then 'list' will be a three-column array with unique pairs in the first two columns and their corresponding occurrence counts in the third column.

Roger Stafford