title: In MATLAB, how can I count the unique number of index values associated with a condition?
body: <p>I have a 2-D matrix containing, in the first column, the index of the experimental condition, and in the second column, the index of the corresponding experiment, i.e. <code>[condition experiment]</code>. Each row corresponds to one interesting event (one experiment can produce one or several events).</p>
  
  <p>Counting conditions and events is easy. I'd like to know how to count how many unique experiments there were for each given condition.</p>
  
  <p>This is the solution I have right now using <a href="http://www.mathworks.com/help/techdoc/ref/accumarray.html" rel="nofollow">ACCUMARRAY</a>, but I think there should be a simpler or more elegant solution:</p>
  
  <pre><code>idxList = [1 1;...  %# There are two experiments for condition 1...
             1 2;...
             1 2;...
             2 1;...  %# ...and 1 experiment for condition 2.
             2 1];
  accumarray(idxList(:,1),idxList(:,2),[],@(x)length(unique(x)))
  ans =
       2
       1
  </code></pre>