MATLAB: Mapping two binary bits to one

bits

I have generate a set of bits 0 and 1,
N=10000;
m=(sign(randn(1,N))+1)/2;
The problem is how do I group the bits? For example
00=-j
01=-1
10=1
11=j

Best Answer

vals = [-1j, -1, 1, 1j];
m2 = reshape(m, 2, []);
idx = m2(1,:) * 2 + m(2,:) + 1;
output = vals(idx);
Related Question