title: Matlab: get rid of loop
body: <p>I am working with binary information, read from file. This is a sequence of numbers, in 40 bit format, where first 8bit should be neglected in my case, and another 32 bits are "shuffled" 32bit single precision IEEE 754 format. This "shuffle" is pretty straightforward: the correct IEEE 754 binary32 I get, when I take following order of bits: 24-32, 17-24, 9-16</p>
  
  <p>All this is simulated with code below. </p>
  
  <p>Question: How can I improve the code below to make it faster, get rid of "for" loop and use efficient MATLAB matrix operations?</p>
  
  <pre><code>a = (1:5*8*1000000)'; % represent indices of bits binary information, read from file
  tic
  a_reshaped = reshape(a, 8, [])'; 
  toc %Elapsed time is 0.176375 seconds.
  n_elem = size(a_reshaped,1)/5;
  result = zeros(n_elem,8*4);
  for i = 1:n_elem
      result(i,:) = [a_reshaped(5*i,:) a_reshaped(5*i-1,:) a_reshaped(5*i-2,:) a_reshaped(5*i-3,:)];
  end
  toc %Elapsed time is 4.243868 seconds.
  </code></pre>