MATLAB: Middle Value gets skipped if the length is odd

integer operands are required for colon operator when used as indexMATLAB

Whenever I tried to divide the odd number the middle value get skipped.
Ex:
A = [ 1 0 1 0 1];
len =length(A);
x = [A(1:(len)/2) A(1+(len)/2:len)];
Integer operands are required for colon operator when used as index
I do not know, How to solve this? Anyone could help me.

Best Answer

After you divide the length by 2, you need to use ceil since 5/2 is 2.5 and there is no 2.5 index but ceil(5/2) = 3, which IS the middle index. Try this code:
A = [ 1 0 1 0 1];
len =length(A) % Not needed -- just for info.
middleIndex = ceil(length(A) / 2) % Will be 3
% Compute x (though x will be the same as the original according to this formula)
x = [A(1:middleIndex), A(1 + middleIndex : end)]
It shows:
len =
5
middleIndex =
3
x =
1 0 1 0 1