title: From a for loop, how do I store different length vectors into a single matrix
body: <p>I'm new to Matlab and programming in general. I'm trying to write a for loop where I'm able to keep the generated uneven length vectors into a matrix.</p>
  
  <p>Here is my basic for loop:</p>
  
  <pre><code>G1 = [1 2 3 4];
  for G1 = G1(1:end)
  y = randn(1,G1)
  end
  </code></pre>
  
  <p>I like to keep all values of y in the successive rows of a matrix like this:</p>
  
  <p><a href="https://i.stack.imgur.com/GGxzA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GGxzA.png" alt="enter image description here"></a></p>
  
  <p>I tried initializing y to a zero matrix first and running the for loop:</p>
  
  <pre><code>G1 = [1 2 3 4];
  for G1 = G1(1:end)
  y = zeros(4,4)
  y(G1,:) = randn(1,G1)
  end
  </code></pre>
  
  <p>The error is "Subscripted assignment dimension mismatch." I have also tried other variations of the for loop, all with initializing the zero matrix first but I received the same error message. How can I go about doing this? Thanks!</p>