:
DEC2BIN AB ( woodchips), BITGET, . REPMAT, ( 32 5):
allCombos = bitget(repmat((0:31)',1,5),repmat(5:-1:1,32,1));
BITGET , :
vec = (0:31)';
allCombos = [bitget(vec,5) bitget(vec,4) bitget(vec,3) ...
bitget(vec,2) bitget(vec,1)];
:
Method | Average Time
-----------------+------------------
DEC2BIN | 0.000788 s
BITGET+REPMAT | 0.000727 s
BITGET x5 | 0.000045 s
, BITGET .
: ( )
If you want to build a matrix of all possible vectors of zeros and ones having a length of 5, this would be one way to do this using the PERMS and UNIQUE functions (since PERMS creates duplicate rows):
allCombos = [0 0 0 0 0;
unique(perms([0 0 0 0 1]),'rows'); ...
unique(perms([0 0 0 1 1]),'rows'); ...
unique(perms([0 0 1 1 1]),'rows'); ...
unique(perms([0 1 1 1 1]),'rows'); ...
1 1 1 1 1];
source
share