12-bit Binary counter matrix in matlab
12-bit Binary counter matrix in matlab
(OP)
Hi all,
I want to make a sort of binary counter in a matrix form to test a dac for inl. at the moment i'm using the zeros and ones function to do a 5 bit counter but i want to extend this to 12 bits(4096 codes) and if i were to continue using the zeros and ones the lsb column would have to be written out 4096 times-not very efficient!
I wonder could anyone help me?
Thanx in advance,
Damien
I want to make a sort of binary counter in a matrix form to test a dac for inl. at the moment i'm using the zeros and ones function to do a 5 bit counter but i want to extend this to 12 bits(4096 codes) and if i were to continue using the zeros and ones the lsb column would have to be written out 4096 times-not very efficient!
I wonder could anyone help me?
Thanx in advance,
Damien





RE: 12-bit Binary counter matrix in matlab
bin_array = zeros(4096,12); % the answer will be stored in this array
bin_str = dec2bin(0:4095,12); % convert each number to a binary string
for digit = 1:12
% pick each binary digit in turn, convert to a number and store in the matrix
bin_array(:,digit) = str2num(bin_str(:,digit));
end
Its the fastest way of doing it that I can think of at present. I can't off-hand think how to remove the loop by vectorisation.
M