title: How to resolve horzcat error in matlab?
body: <p>I did some processing on a 2-D binary matrix using a cell array to store information based upon equal values of elements. I have <code>15</code> cells, two of which are as follows:</p>
  
  <pre><code>similarity{1} = [2 5 8 10 12 13 18 19 20 21 22 23];
  similarity{2} = [2 5 8  13 18 19 20 21 22 23];
  </code></pre>
  
  <p>... until <code>similarity{n}</code> values in <code>similarity{1,..n}=n</code>.</p>
  
  <p>When I run the following code</p>
  
  <pre><code>similarity = cellfun(@unique, similarity, 'UniformOutput', false);
  numsInCell = unique([similarity{:}]);                  % numbers in cell, sorted
  
  for n = numsInCell % loop over numbers in cell
      lSetIs1 = cellfun(@numel,similarity) == 1;         % length of set is 1
       nInSet = cellfun(@(set) any(set==n), similarity); % set contains n
       nIsUnique = sum(nInSet(:))==1;                    % n occurs once
       condition = ~nIsUnique &amp; ~any(nInSet(:) &amp; lSetIs1(:));
  
       % if false for all sets...
       if condition
           similarity = cellfun(@(set) set(set~=n), similarity, 'UniformOutput',false); 
       end
  end 
  </code></pre>
  
  <p>I get following error</p>
  
  <blockquote>
    <p>Error using horzcat <br> 
    Dimensions of matrices being concatenated are not consistent.</p>
  </blockquote>
  
  <p>and </p>
  
  <blockquote>
    <p>Error in @(set)any(set==n)</p>
  </blockquote>
  
  <p>Can anyone help me identify where I made a mistake?</p>