title: Concatenating (sub)fields of structs in a cell array
body: <p>I have a Matlab object, that is a cell array containting structs that have almost identical structures and I want to programmatically get a (sub)field of the structs of all cell array elements.</p>
  
  <p>For example, we take <code>test</code></p>
  
  <pre><code>test = {struct('a',struct('sub',1)), struct('a',struct('sub',2),'b',1)};
  </code></pre>
  
  <p>This will create a cell array with the following structure:</p>
  
  <pre><code>cell-element 1: a --&gt; sub --&gt; 1
  cell-element 2: a --&gt; sub --&gt; 2
                    \-&gt; b --&gt; 1
  </code></pre>
  
  <p>It can be seen that the elements of <code>test</code> don't have the exact same structure, but similar. How can I get all values of the <code>a.sub</code> fields of the elements of the cell. I can obtain them in this specific problem with</p>
  
  <pre><code>acc=zeros(1,numel(test));
  for ii=1:numel(test)
     acc(ii) = test{ii}.a.sub;
  end
  </code></pre>
  
  <p>but I can't quite get this method to work in a more general context (ie. having different fields).</p>