title: How to choose identical values in a cell array with constraints using Matlab?
body: <p>If I have a 4x1 Cell structure with that represents <code>a=[A1 A2 A3 A4]</code> : </p>
  
  <pre><code>a=cell(4,1)
  a{1}=[1 3 1 0]
  a{2}=[3 3 3 3]
  a{3}=[3 2 3 2]
  a{4}=[3 3 3 2]
  
  B=[1 1 1 2]; %priority
  </code></pre>
  
  <p><strong>I would like to do the following :</strong></p>
  
  <p>Pick cells that correspond to priority <code>B=[1 1 1 2]</code> (where <code>B=1</code> is highest priority and <code>A=3</code>)<br>
  Which means, find any cell that begins with [3 3 3 #], where all their priority is 1's in <code>B</code>.</p>
  
  <p>ideal answer should be :     <code>a{2}</code>=<code>[3 3 3 3]</code> and <code>a{4}</code> = <code>[3,3,3,2]</code> </p>
  
  <hr>
  
  <p>My try is to add this :</p>
  
  <pre><code>[P arrayind]=min(B) % problem is that arrayind return index=1 only .. not all indices
  if P==1
     arrayindex = 1:4 ; %look at each index of the array
     c = a(cellfun(@(x) ismember(x(arrayindex), 3), a));
  end
  </code></pre>
  
  <p>However this gives me an error stating :</p>
  
  <pre><code>Error using cellfun
  Non-scalar in Uniform output, at index 1, output 1.
  Set 'UniformOutput' to false.
  </code></pre>
  
  <p>By adjusting the code to accommodate this error :</p>
  
  <pre><code>c = a(cellfun(@(x) ismember(x(arrayindex), 3), a,'UniformOutput',false));
  
  I get this error :
  
  Error using subsindex
  Function 'subsindex' is not defined for values of class 'cell'.
  </code></pre>
  
  <p>And now I'm stuck at this point.</p>