title: How do i handle "Error using vertcat Dimensions of matrices being concatenated are not consistent" in Matlab?
body: <p>So I want to concatenate an <code>m x n</code> matrix to obtain a <code>1 x mn</code> matrix. The matrix I want to concatenate are generated from a while loop. Although the number of columns will always be <code>3</code>, I however cannot tell how many rows there will be for each iteration. Also, the row sizes for each iteration may not always be the same. </p>
  
  <p>The code runs in cases where the row sizes were all equal to <code>6</code>, but in cases where they aren't equal I get an error: </p>
  
  <blockquote>
    <p>Error using vertcat Dimensions of matrices being concatenated are not consistent.</p>
  </blockquote>
  
  <p>parts of the code are as follows:</p>
  
  <pre><code>A = [];
  B = [];
  searchArea = 2;
  
  for ii = 1: numel(velocity)
      Do ....
      while area(ii,:) &lt; searchArea
          Do ....
          % COLLATE vectors for A
          A = [A; [Ax(ii), Ay(ii), Az(ii)]];
          Do ...
      end
      %# Copy the A into new variable (B) and Reshape into row vector so as to associate each row to its corresponding velocity
      B = [B; reshape(A.',1,[])];
      A = [];
  end
  </code></pre>
  
  <p>Could someone please advice me on what I am doing wrong here. I would clarify further if there be need. Thanks guys!</p>