title: How to loop through nested struct fields in MATLAB
body: <p>I have data on several subjects that each performed several trials of an activity.  I have read all the data into structs in the format
      subject(1).trial(1).something
      subject(1).trial(2).somethingelse
  etc.</p>
  
  <p>Now I need to read each of the trials into a row a big matrix [A] to perform some calculations on each trial, as if the subject didn't matter.  So I started with this:</p>
  
  <pre><code>for i = 2:numSubjects
      for j = 1:numTrials
      A(j,:) = cat(2,subject(i).trial(j).torque_integral,     subject(i).trial(j).work_integral); 
      end
  end
  </code></pre>
  
  <p>But this will only work for the first subject.  When the subject (i) increments to 3, the trial (j) will be back at one.  So the idea is the output A lines up like this: </p>
  
  <p>subject|trial|A </p>
  
  <p>1          1        1</p>
  
  <p>1          2        2</p>
  
  <p>1          3        3 </p>
  
  <p>2          1        4</p>
  
  <p>2          2        5</p>
  
  <p>2          3        6</p>
  
  <p>Hopefully this is clear.  Any thoughts?</p>