]> AND Private Git Repository - canny.git/blob - stc/exp/ml_stc_linux_make_v1.0/matlab/STC matlab implementation/dec2binvec.m
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
75a8c90bdab6b61fe247085804b7bd5f3f249d62
[canny.git] / stc / exp / ml_stc_linux_make_v1.0 / matlab / STC matlab implementation / dec2binvec.m
1 function out = dec2binvec(dec,n)
2 %DEC2BINVEC Convert decimal number to a binary vector.
3 %
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. 
7
8 %    DEC2BINVEC(D,N) produces a binary representation with at least
9 %    N bits.
10
11 %    Example:
12 %       dec2binvec(23) returns [1 1 1 0 1]
13 %
14 %    See also BINVEC2DEC, DEC2BIN.
15 %
16
17 %    MP 11-11-98
18 %    Copyright 1998-2003 The MathWorks, Inc.
19 %    $Revision: 1.5.2.4 $  $Date: 2003/08/29 04:40:56 $
20
21 % Error if dec is not defined.
22 if nargin < 1
23    error('daq:dec2binvec:argcheck', 'D must be defined.  Type ''daqhelp dec2binvec'' for more information.');
24 end
25
26 % Error if D is not a double.
27 if ~isa(dec, 'double')
28    error('daq:dec2binvec:argcheck', 'D must be a double.');
29 end
30
31 % Error if a negative number is passed in.
32 if (dec < 0)
33    error('daq:dec2binvec:argcheck', 'D must be a positive integer.');
34 end
35
36 % Convert the decimal number to a binary string.
37 switch nargin
38 case 1
39    out = dec2bin(dec);
40 case 2
41    out = dec2bin(dec,n);
42 end
43
44 % Convert the binary string, '1011', to a binvec, [1 1 0 1].
45 out = logical(str2num([fliplr(out);blanks(length(out))]')');