1 function out = dec2binvec(dec,n)
2 %DEC2BINVEC Convert decimal number to a binary vector.
4 % DEC2BINVEC(D) returns the binary representation of D as a binary
5 % vector. The least significant bit is represented by the first
6 % column. D must be a non-negative integer.
8 % DEC2BINVEC(D,N) produces a binary representation with at least
12 % dec2binvec(23) returns [1 1 1 0 1]
14 % See also BINVEC2DEC, DEC2BIN.
18 % Copyright 1998-2003 The MathWorks, Inc.
19 % $Revision: 1.5.2.4 $ $Date: 2003/08/29 04:40:56 $
21 % Error if dec is not defined.
23 error('daq:dec2binvec:argcheck', 'D must be defined. Type ''daqhelp dec2binvec'' for more information.');
26 % Error if D is not a double.
27 if ~isa(dec, 'double')
28 error('daq:dec2binvec:argcheck', 'D must be a double.');
31 % Error if a negative number is passed in.
33 error('daq:dec2binvec:argcheck', 'D must be a positive integer.');
36 % Convert the decimal number to a binary string.
44 % Convert the binary string, '1011', to a binvec, [1 1 0 1].
45 out = logical(str2num([fliplr(out);blanks(length(out))]')');