MATLAB: How to read and manipulate binary numbers

binarycell arrays

Hi,
Im currently working with binary numbers within matlab, however they are read into my code as single numbers eg. 10001011 etc. However, I need to break up the code so I can examine different parts. Is there a way of breaking a single number into a 2 or more cell array.
For Example, starting with 10001011
broken up to a 1x4 array of [10 00 10 11]
Id appreciate any help, Thanks! Mark

Best Answer

Strictly speaking, this should do it:
>> a = [1 0 0 0 1 0 1 1];
>> b = 10*a(1:2:end) + a(2:2:end)
b =
10 0 10 11
Or, if you've got a string of 1's and 0's:
>> a = '10001011';
>> arrayfun(@(i)a(i:i+1),1:2:length(a),'uniformoutput',false)
ans =
'10' '00' '01' '11'
Note: both of these solutions assume that you have an even number of digits. They'll croak if you pass in an odd number of digits.