title: How can I shift array element using a for loop in Matlab?
body: <p>I'm trying to shift all the elements of an array to the left, so that the first element would become the last element, the second becomes the first, the third the second, etc. I know about the <code>circshift</code> commands, but I would like to do this using a for loop.</p>
  
  <p>Here's what I did.</p>
  
  <pre><code>old=[]
  n=length(old)
  for i=1;i&lt;(n-1);i=i+1;
      for j=2;j&lt;n;j=j+1;
          new(j)=old(i)
      end
  end 
  </code></pre>
  
  <p>But it of course didn't work. I'm having trouble figuring out to make an array of n elements, without specifying n, which is why I used old=[], but I think that created an array of 0 elements.</p>
  
  <p>How can I make this code work?</p>