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$>
References: <imt4a8$nh$>
Reply-To: <HIDDEN>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: 1301426823 13023 (29 Mar 2011 19:27:03 GMT)
NNTP-Posting-Date: Tue, 29 Mar 2011 19:27:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1187260
Xref: comp.soft-sys.matlab:718895

"Amanda " <> wrote in message <imt4a8$nh$>...
> 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