help me solve errors in this code
Show older comments
function out = dec2binvec(dec,n)
%DEC2BINVEC Convert decimal number to a binary vector.
%
% DEC2BINVEC(D) returns the binary representation of D as a binary
% vector. The least significant bit is represented by the first
% column. D must be a non-negative integer.
%
% DEC2BINVEC(D,N) produces a binary representation with at least
% N bits.
%
% Example:
% dec2binvec(23) returns [1 1 1 0 1]
%
% See also BINVEC2DEC, DEC2BIN.
%
% MP 11-11-98
% Copyright 1998-2003 The MathWorks, Inc.
% $Revision: 1.5.2.4 $ $Date: 2003/08/29 04:40:56 $
% Error if dec is not defined.
if nargin < 1
error('daq:dec2binvec:argcheck', 'D must be defined. Type ''daqhelp dec2binvec'' for more information.');
end
% Error if D is not a double.
if ~isa(dec, 'double')
error('daq:dec2binvec:argcheck', 'D must be a double.');
end
% Error if a negative number is passed in.
if (dec < 0)
error('daq:dec2binvec:argcheck', 'D must be a positive integer.');
end
% Convert the decimal number to a binary string.
switch nargin
case 1
out = dec2bin(dec);
case 2
out = dec2bin(dec,n);
end
% Convert the binary string, '1011', to a binvec, [1 1 0 1]
out = logical(STR2NUM([fliplr(out);blanks(length(out))]')');
I get error in this code please help me.??? errors are mentioned below
Error using ==> vertcat
CAT arguments dimensions are not consistent.
Error in ==> dec2binvec at 45
out = logical(STR2NUM([fliplr(out);blanks(length(out))]')');
Answers (1)
Walter Roberson
on 16 Nov 2015
You are calling the routine incorrectly. You are calling it with a vector or array rather than a scalar. dec2binvec() accepts only a scalar input. Your code for ReadBinFile is incorrect in calling
bits_tmp = dec2binvec(outBytes')';
It is not clear what it is expecting, but I suspect that it could be written as
bits_tmp = dec2bin(outBytes')' - '0';
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!