title: Is there a function for this in MATLAB?
body: <p>Consider the following example, for a user specified odd number of <code>N = 5</code> one should see the following output:</p>
  <p><code> A = [1 4 2 5 3];</code></p>
  <p>For <code>N = 7</code>: <code> A = [1 5 2 6 3 7 4];</code></p>
  <p>In more general form for an odd number <code>N</code>:</p>
  <p><code>A = [1 ceil(N/2+1) 2 ceil(N/2+2) ... N ceil(N/2)];</code></p>
  <p>I went about the problem like this</p>
  <pre><code>A = zeros(1, N);
  a1 = 1:ceil(N/2): a2 = ceil(N/2+1):N;
  j = 1; k = 1; 
  
  for i = 1:N
      if rem(i, 2) ~= 0
          A(i) = a1(j);
          j = j+1;
      else 
          A(i) = a2(k);
          k = k+1;
      end
  end 
  </code></pre>
  <p>I feel that there are better ways of coding the problem, optimisation and simplicity-wise. I would appreciate it if you could guide me toward what I am seeking.</p>