From: Ujjwal Verma on
"Ujjwal Verma" <toto(a)gt.tyuu> wrote in message <htlnki$7m0$1(a)fred.mathworks.com>...
> "us " <us(a)neurol.unizh.ch> wrote in message <htlmb8$bim$1(a)fred.mathworks.com>...
> > "Ujjwal Verma"
> > > Mine version is 7.6.0.324 (R2008a) .
> > > daq toolbox is 2.12
> > >
> > > which dec2binvec n dec2bin gives this
> > > C:\Program Files\MATLAB\R2008a\toolbox\daq\daq\dec2binvec.m and
> > > C:\Program Files\MATLAB\R2008a\toolbox\matlab\strfun\dec2bin.m resp
> >
> > hmm......
> >
> > dec2binvec(65,7)
> > % ans = 1 0 0 0 0 0 1
> > dec=65;
> > dec2binvec(dec,7)
> > % ans = 1 0 0 0 0 0 1
> > % what do you get with
> > dec2bin(dec,7)
> > % ans = 1000001
> > % also,
> > edit dec2binvec; % <- don't touch it, though
> > % put a break right before the line (r2010a!)
> > % out = logical(str2num([fliplr(out);blanks(length(out))]')');
> > % run your example, then inspect the var OUT before this conversion...
> >
> > us
>
> i tried now with dec=29 and found that
> out =
>
> 0011100
>
> If we do the other way around,ie if we suppose
> binary =
>
> 1 0 1 1 1 0 0
>
> then binvec2dec(binary) gives
>
> ans =
>
> 29

I found an interesting stuff. While reviewing dec2bin in debug mode (just before s=char(rem(floor(d*pow2(1-max(n,e):0)),2)+'0');), I found that if I execute this line as it is (ie with all the variable name as it is), we get this

char(rem(floor(d*pow2(1-max(n,e):0)),2)+'0')

ans =

0011100

(NOTE: here d=29)

but when I replace the value of d with 29 I got this

char(rem(floor(29*pow2(1-max(n,e):0)),2)+'0')

ans =

0011101
From: us on
"Ujjwal Verma"
> > edit dec2binvec; % <- don't touch it, though
> > % put a break right before the line (r2010a!)
> > % out = logical(str2num([fliplr(out);blanks(length(out))]')');
> > % run your example, then inspect the var OUT before this conversion...
> >
> > us
>
> i tried now with dec=29 and found that
> out =
> 0011100

well... where does this OUT comre from
- val BEFORE conversion in the above line of DEC2BINVEC(?)...

% here, and most everywhere...
dec2bin(29,7)
% ans = 0011101

us
From: Ujjwal Verma on
"us " <us(a)neurol.unizh.ch> wrote in message <htlo5r$e1j$1(a)fred.mathworks.com>...
> "Ujjwal Verma"
> > > edit dec2binvec; % <- don't touch it, though
> > > % put a break right before the line (r2010a!)
> > > % out = logical(str2num([fliplr(out);blanks(length(out))]')');
> > > % run your example, then inspect the var OUT before this conversion...
> > >
> > > us
> >
> > i tried now with dec=29 and found that
> > out =
> > 0011100
>
> well... where does this OUT comre from
> - val BEFORE conversion in the above line of DEC2BINVEC(?)...
>
> % here, and most everywhere...
> dec2bin(29,7)
> % ans = 0011101
>
> us

yes it comes from dec2bin (switch case). I have rather spotted the place of error, its in the last line of dec2bin s=char(rem(floor(d*pow2(1-max(n,e):0)),2)+'0');
(cf my last post)
From: us on
"Ujjwal Verma"
> yes it comes from dec2bin (switch case). I have rather spotted the place of error, its in the last line of dec2bin s=char(rem(floor(d*pow2(1-max(n,e):0)),2)+'0');
> (cf my last post)

sorry, didn't see your post before i replied...
anyhow, this is REALLY strange, not to say: inexplicable...
DEC2BIN has been around for ages without any complaint... and as far as i know its subroutines, eg, LOG2, POW2, have not been reported as being buggy (your r2008 or before)...
here, DEC2BIN works as expected...
note, though
% Copyright 1984-2009 The MathWorks, Inc.
% $Revision: 1.13.4.9 $ $Date: 2009/08/14 04:01:50 $
and the relevant lines are

d = double(d);
if nargin<2
n=1; % Need at least one digit even for 0.
else
if ~(isnumeric(n) || ischar(n)) || ~isscalar(n) || n<0
error('MATLAB:dec2bin:InvalidBitArg','N must be a positive scalar numeric.');
end
n = double(n);
n = round(n); % Make sure n is an integer.
end;
%
% Actual algorithm
%
[f,e]=log2(max(d)); % How many digits do we need to represent the numbers?
s=char(rem(floor(d*pow2(1-max(n,e):0)),2)+'0');

unfortunately, we don't run earlier versions anymore...
therefore, i cannot check your data...

us
From: Ujjwal Verma on
"us " <us(a)neurol.unizh.ch> wrote in message <htlqcm$c0e$1(a)fred.mathworks.com>...
> "Ujjwal Verma"
> > yes it comes from dec2bin (switch case). I have rather spotted the place of error, its in the last line of dec2bin s=char(rem(floor(d*pow2(1-max(n,e):0)),2)+'0');
> > (cf my last post)
>
> sorry, didn't see your post before i replied...
> anyhow, this is REALLY strange, not to say: inexplicable...
> DEC2BIN has been around for ages without any complaint... and as far as i know its subroutines, eg, LOG2, POW2, have not been reported as being buggy (your r2008 or before)...
> here, DEC2BIN works as expected...
> note, though
> % Copyright 1984-2009 The MathWorks, Inc.
> % $Revision: 1.13.4.9 $ $Date: 2009/08/14 04:01:50 $
> and the relevant lines are
>
> d = double(d);
> if nargin<2
> n=1; % Need at least one digit even for 0.
> else
> if ~(isnumeric(n) || ischar(n)) || ~isscalar(n) || n<0
> error('MATLAB:dec2bin:InvalidBitArg','N must be a positive scalar numeric.');
> end
> n = double(n);
> n = round(n); % Make sure n is an integer.
> end;
> %
> % Actual algorithm
> %
> [f,e]=log2(max(d)); % How many digits do we need to represent the numbers?
> s=char(rem(floor(d*pow2(1-max(n,e):0)),2)+'0');
>
> unfortunately, we don't run earlier versions anymore...
> therefore, i cannot check your data...
>
> us

Thanks a lot for your help,I really appreciate that.....Even I am unable to understand the reason behind this....

Though I noticed a slight difference in the version number ($Revision: 1.13.4.6) but I am unable to spot any difference in the code.
% Hans Olsson, hanso(a)dna.lth.se 3-23-95
% Copyright 1984-2006 The MathWorks, Inc.
% $Revision: 1.13.4.6 $ $Date: 2006/11/11 22:45:00 $

if nargin<1
error(nargchk(1,2,nargin,'struct'));
end
if isempty(d)
s = '';
return;
end

d = d(:); % Make sure d is a column vector.
if ~(isnumeric(d) || islogical(d) || ischar(d))
error('MATLAB:dec2bin:InvalidDecimalArg','D must be numeric.');
end
d = double(d);

if nargin<2
n=1; % Need at least one digit even for 0.
else
if ~(isnumeric(n) || ischar(n)) || ~isscalar(n) || n<0
error('MATLAB:dec2bin:InvalidBitArg','N must be a positive scalar numeric.');
end
n = double(n);
n = round(n); % Make sure n is an integer.
end;

%
% Actual algorithm
%
[f,e]=log2(max(d)); %#ok How many digits do we need to represent the numbers?
s=char(rem(floor(d*pow2(1-max(n,e):0)),2)+'0');