Interleave and Deinterleave a vector into two new vectors
<p><strong>Interleaver:</strong> Assume we have vector <code>X= randi(1,N)</code> I would like to split the contents of <code>X</code> into two new vectors <code>X1</code>and <code>X2</code> such that the first element of <code>X</code> is the first element of <code>X1</code>, the first element of <code>X2</code> is the second element of <code>X</code>, the third element of <code>X</code> is the second element of <code>X1</code> and the fourth element of <code>X</code> is the second element of <code>X2</code>... etc till the last element of the vector `X.</p>
<p>I have the following idea</p>
<pre><code>X1(1)=X(1);
X2(1)=X(2);


for i=1:length(X)
X1(i)= X(i+2);
end
for j=2:length (X)
X2(i)= X(i+2)
end
</code></pre>
<p>My question is: is my method correct? is there a better way to do it?</p>
<p><strong>Deinterleaver</strong>
I also have the reverse problem so basically in this case I have <code>X1</code> and <code>X2</code> and would like to recover <code>X</code>, how would I efficiently recover <code>X</code>?</p>