title: How to write this in an elegant way (cell arrays and structs in MATLAB)
body: <p>I would like to <strong>plot connected points</strong> in MATLAB. </p>
  
  <p>My connected points come from connecting objects of <em>"stats"</em>, where each <em>"stat"</em> comes from a <strong>BW regionprops</strong> struct.</p>
  
  <p>The code I have written works, but it suffers from a lot of <em>"ugliness"</em>, which I couldnt fix even after trying various ways.</p>
  
  <pre><code>function plot_line( line )
  
  a = cell2mat(line);
  b = {a.Centroid};
  
  matx = {};
  maty = {};
  
  for i = 1:size(b,2)
      matx{end+1} = b{i}(1);
      maty{end+1} = b{i}(2);
  end
  
  plot ( cell2mat(matx), cell2mat(maty) );
  
  end
  </code></pre>
  
  <p>Can you help me make this code nicer? It's not critical, as my code works fine and as the lines are short (&lt;100 points) the performance is not an issue.</p>
  
  <p>It is just that it would be really nice to know how this tiny function <strong>should be written</strong> in the proper way, without for loops and 3 calls of cell2mat.</p>
  
  <p>In my example:</p>
  
  <ul>
  <li>line is a <code>&lt;1xn cell&gt;</code>, </li>
  <li><code>line{1}</code> has a property <code>'Centroid'</code> and </li>
  <li><code>line{i}.Centroid(1)</code> are the x coordinates and </li>
  <li><code>line{i}.Centroid(2)</code> are the y coordinates.</li>
  </ul>
  
  <p>Actually, all I need is plotting <code>line{i}.Centroid(1)</code>, <code>line{i}.Centroid(2)</code> for <code>i = 1:size(line,2)</code>, but I don't know how.</p>