MATLAB: How to sort even and odds elements in an array or vector recursively

sorting; even and odd arre sort

Hi,
I am trying to sort an array of 1xN in different odd and even arrays till the length last array =4 for example: X=1:32; N=length(X) m=log2(N);
for i=1:m
A=X(1,1:2:end); %for odd bits B=X(1,2:2:end); %for even bits X=A;
if l=4 break end
a=B(1,1:2:end); %for odd bits b=B(1,2:2:end); %for even bits B=a; end
i m getting output for X=1:16 but if I increase length of X to N then its is not working; for X=1:32, I am getting only odd values
i want the o/p as [1 9 17 25 5 13 21 29 3 11 19 27 7 15 23 31 2 10 18 26 6 14 22 30 4 12 20 28 8 16 24 32]
In my code it is considering odd bits only. I want to do this for N bit but my loop is not working in that case. Please help me out
Thanks in advance

Best Answer

Hi,
I don't really get your intention. What are A, B, a and b for?
And where do you compute l for the if-statement?
It would be helpful if you edited your code.