Generate matrix of bits

后端 未结 3 495
别跟我提以往
别跟我提以往 2021-01-21 04:52

I would like to take an integer n defining the number of bits in my communication code and a vector defining the alphabet I am assigning to bits 0:n-1,

3条回答
  •  -上瘾入骨i
    2021-01-21 05:04

    You can also do it like this:

    M = 2 * (dec2bin(0:7, 3)=='1')-1;
    

    That returns:

    M =
        -1    -1    -1
        -1    -1     1
        -1     1    -1
        -1     1     1
         1    -1    -1
         1    -1     1
         1     1    -1
         1     1     1
    

    However, it's slower. I get 0.0012s (dec2bin) against 0.0002s (meshgrid+bitget) for 1024 values and 10 bits.

提交回复
热议问题