<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
  <channel>
    <link>http://www.mathworks.ch/matlabcentral/newsreader/view_thread/305296</link>
    <title>MATLAB Central Newsreader - Counting Genotypes from Alleles</title>
    <description>Feed for thread: Counting Genotypes from Alleles</description>
    <language>en-us</language>
    <copyright>&amp;copy;1994-2013 by MathWorks, Inc.</copyright>
    <webmaster>webmaster@mathworks.com</webmaster>
    <generator>MATLAB Central Newsreader</generator>
    <docs>http://blogs.law.harvard.edu/tech/rss</docs>
    <ttl>60</ttl>
    <image>
      <title>MathWorks</title>
      <url>http://www.mathworks.ch/images/membrane_icon.gif</url>
    </image>
    <item>
      <pubDate>Tue, 29 Mar 2011 17:19:04 +0000</pubDate>
      <title>Counting Genotypes from Alleles</title>
      <link>http://www.mathworks.ch/matlabcentral/newsreader/view_thread/305296#828109</link>
      <author>Amanda </author>
      <description>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.&lt;br&gt;
&lt;br&gt;
For example for the following vector, how many times does A occur in column 1 along with A in column 2. &lt;br&gt;
vec=[A A&lt;br&gt;
A A&lt;br&gt;
A A&lt;br&gt;
A a&lt;br&gt;
A A&lt;br&gt;
a a]&lt;br&gt;
Where the answer would be 4. &lt;br&gt;
Thank you!</description>
    </item>
    <item>
      <pubDate>Tue, 29 Mar 2011 17:31:04 +0000</pubDate>
      <title>Re: Counting Genotypes from Alleles</title>
      <link>http://www.mathworks.ch/matlabcentral/newsreader/view_thread/305296#828115</link>
      <author>Sean de </author>
      <description>"Amanda " &amp;lt;ahulse@tamu.edu&amp;gt; wrote in message &amp;lt;imt4a8$nh$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; For example for the following vector, how many times does A occur in column 1 along with A in column 2. &lt;br&gt;
&amp;gt; vec=[A A&lt;br&gt;
&amp;gt; A A&lt;br&gt;
&amp;gt; A A&lt;br&gt;
&amp;gt; A a&lt;br&gt;
&amp;gt; A A&lt;br&gt;
&amp;gt; a a]&lt;br&gt;
&amp;gt; Where the answer would be 4. &lt;br&gt;
&amp;gt; Thank you!&lt;br&gt;
&lt;br&gt;
Assuming you can have numeric values instead of letters:&lt;br&gt;
example:&lt;br&gt;
&lt;br&gt;
A = [1 1; 2 3; 1 3; 1 1; 1 1; 2 3; 3 4; 2 4; 1 1]&lt;br&gt;
N =  sum(all(bsxfun(@eq,A,[1 1]),2)) %how many [1 1]s</description>
    </item>
    <item>
      <pubDate>Tue, 29 Mar 2011 17:52:22 +0000</pubDate>
      <title>Re: Counting Genotypes from Alleles</title>
      <link>http://www.mathworks.ch/matlabcentral/newsreader/view_thread/305296#828126</link>
      <author>Florin Neacsu</author>
      <description>"Amanda " &amp;lt;ahulse@tamu.edu&amp;gt; wrote in message &amp;lt;imt4a8$nh$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; For example for the following vector, how many times does A occur in column 1 along with A in column 2. &lt;br&gt;
&amp;gt; vec=[A A&lt;br&gt;
&amp;gt; A A&lt;br&gt;
&amp;gt; A A&lt;br&gt;
&amp;gt; A a&lt;br&gt;
&amp;gt; A A&lt;br&gt;
&amp;gt; a a]&lt;br&gt;
&amp;gt; Where the answer would be 4. &lt;br&gt;
&amp;gt; Thank you!&lt;br&gt;
&lt;br&gt;
Hi,&lt;br&gt;
&lt;br&gt;
try ismember :&lt;br&gt;
&amp;gt;sum(ismember(vec,[A A],'rows'))&lt;br&gt;
&lt;br&gt;
Regards,&lt;br&gt;
Florin</description>
    </item>
    <item>
      <pubDate>Tue, 29 Mar 2011 19:27:03 +0000</pubDate>
      <title>Re: Counting Genotypes from Alleles</title>
      <link>http://www.mathworks.ch/matlabcentral/newsreader/view_thread/305296#828138</link>
      <author>Roger Stafford</author>
      <description>"Amanda " &amp;lt;ahulse@tamu.edu&amp;gt; wrote in message &amp;lt;imt4a8$nh$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; 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.&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; For example for the following vector, how many times does A occur in column 1 along with A in column 2. &lt;br&gt;
&amp;gt; vec=[A A&lt;br&gt;
&amp;gt; A A&lt;br&gt;
&amp;gt; A A&lt;br&gt;
&amp;gt; A a&lt;br&gt;
&amp;gt; A A&lt;br&gt;
&amp;gt; a a]&lt;br&gt;
&amp;gt; Where the answer would be 4. &lt;br&gt;
&amp;gt; Thank you!&lt;br&gt;
- - - - - - - - - - -&lt;br&gt;
&amp;nbsp;&amp;nbsp;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.&lt;br&gt;
&lt;br&gt;
&amp;nbsp;[u,~,n] = unique(vec,'rows');&lt;br&gt;
&amp;nbsp;list = [u,diff(find([true;diff(sort(n))&amp;gt;0;true]))];&lt;br&gt;
&lt;br&gt;
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.&lt;br&gt;
&lt;br&gt;
Roger Stafford</description>
    </item>
    <item>
      <pubDate>Tue, 29 Mar 2011 19:29:21 +0000</pubDate>
      <title>Re: Counting Genotypes from Alleles</title>
      <link>http://www.mathworks.ch/matlabcentral/newsreader/view_thread/305296#828139</link>
      <author>Amanda </author>
      <description>"Florin Neacsu" &amp;lt;fneacsu2@gmail.com&amp;gt; wrote in message &amp;lt;imt68m$4s1$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; "Amanda " &amp;lt;ahulse@tamu.edu&amp;gt; wrote in message &amp;lt;imt4a8$nh$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; 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.&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; For example for the following vector, how many times does A occur in column 1 along with A in column 2. &lt;br&gt;
&amp;gt; &amp;gt; vec=[A A&lt;br&gt;
&amp;gt; &amp;gt; A A&lt;br&gt;
&amp;gt; &amp;gt; A A&lt;br&gt;
&amp;gt; &amp;gt; A a&lt;br&gt;
&amp;gt; &amp;gt; A A&lt;br&gt;
&amp;gt; &amp;gt; a a]&lt;br&gt;
&amp;gt; &amp;gt; Where the answer would be 4. &lt;br&gt;
&amp;gt; &amp;gt; Thank you!&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Hi,&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; try ismember :&lt;br&gt;
&amp;gt; &amp;gt;sum(ismember(vec,[A A],'rows'))&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Regards,&lt;br&gt;
&amp;gt; Florin&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
Thank you!</description>
    </item>
    <item>
      <pubDate>Tue, 29 Mar 2011 21:14:20 +0000</pubDate>
      <title>Re: Counting Genotypes from Alleles</title>
      <link>http://www.mathworks.ch/matlabcentral/newsreader/view_thread/305296#828157</link>
      <author>Florin Neacsu</author>
      <description>"Amanda " &amp;lt;ahulse@tamu.edu&amp;gt; wrote in message &amp;lt;imtbuh$f61$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; "Florin Neacsu" &amp;lt;fneacsu2@gmail.com&amp;gt; wrote in message &amp;lt;imt68m$4s1$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; "Amanda " &amp;lt;ahulse@tamu.edu&amp;gt; wrote in message &amp;lt;imt4a8$nh$1@fred.mathworks.com&amp;gt;...&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; 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.&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; For example for the following vector, how many times does A occur in column 1 along with A in column 2. &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; vec=[A A&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; A A&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; A A&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; A a&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; A A&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; a a]&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Where the answer would be 4. &lt;br&gt;
&amp;gt; &amp;gt; &amp;gt; Thank you!&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Hi,&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; try ismember :&lt;br&gt;
&amp;gt; &amp;gt; &amp;gt;sum(ismember(vec,[A A],'rows'))&lt;br&gt;
&amp;gt; &amp;gt; &lt;br&gt;
&amp;gt; &amp;gt; Regards,&lt;br&gt;
&amp;gt; &amp;gt; Florin&lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; &lt;br&gt;
&amp;gt; Thank you!&lt;br&gt;
&lt;br&gt;
Hi,&lt;br&gt;
&lt;br&gt;
You're welcome.&lt;br&gt;
&lt;br&gt;
Also, you should take into consideration Roger's suggestion (it provides more information). In case you are using chars and not integers for a and A, then use&lt;br&gt;
&lt;br&gt;
&amp;gt;list = [u,num2str(diff(find([true;diff(sort(n))&amp;gt;0;true])))];&lt;br&gt;
&lt;br&gt;
Regards,&lt;br&gt;
Florin</description>
    </item>
  </channel>
</rss>
