Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

12-bit Binary counter matrix in matlab

Status
Not open for further replies.

damien21

Electrical
Nov 25, 2002
1
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
 
Replies continue below

Recommended for you

This should do it

Code:
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor