help me correct error

%%Test Lempel-Ziv decoder lz_decode.m by decoding data in check.txt.lz
clear all;
% Read binary file, where first byte is used to
% indicate # zeros padded at the end
code = ReadBinFile('check.txt.lz');
% Decode file using lz_decode (to be written)
dec = lz_decode(code);
% Write result to output file. Here, no zero-padding will be performed!
WriteFile('check.txt.dec', dec);
i get this error
Error in ==> check at 6
code = ReadBinFile('check.txt.lz');

3 Commenti

Adam
Adam il 16 Nov 2015
Is that the entire error message?
I would imagine it can't find the file 'check.txt.lz' without either it being on your path or being given a full path to the file, but it could also be that ReadBinFile is a function containing an error or one not found on the path. I assume the full error message would give a clear direction on which of these or something different it is.
Geoff Hayes
Geoff Hayes il 16 Nov 2015
Maida - are there any more lines to the error that you observed (and if so could you copy and paste them to your question)? Is the ReadBinFile a function that you have written? Do you need to specify the path to the file check.txt.lz?
Maida Abbasi
Maida Abbasi il 17 Nov 2015
Modificato: Walter Roberson il 17 Nov 2015
this is the only error i get. ReadBinFile is an m file having following code.
function [outBits, outBytes] = ReadBinFile(FileName)
% [outBits outBytes] = ReadBinFile(FileName)
%
% Read data from file. The first byte is interpreted as integer and
% determines the number of zero-padded bits at the end.
%
% FileName: Name of file
% outBits: bit vector containing the bits of the file
% outBytes: bit vector containing the bytes of the file
fid = fopen('check.txt.lz');
fileBytes = fread(fid)';
% First byte contains padding information
paddBits = fileBytes(1);
outBytes = fileBytes(2:end);
bits_tmp = dec2binvec(outBytes')';
outBits = reshape(bits_tmp(1:end-paddBits),1,numel(bits_tmp)-paddBits);
fclose(fid);

Accedi per commentare.

Risposte (1)

Walter Roberson
Walter Roberson il 17 Nov 2015
At the MATLAB command line, give the command
dbstop if error
and run the program. When it stops, show us the complete error message that is output.

4 Commenti

Maida Abbasi
Maida Abbasi il 17 Nov 2015
Modificato: Walter Roberson il 17 Nov 2015
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))]')');
it stopped at
out = logical(STR2NUM([fliplr(out);blanks(length(out))]')');
Maida Abbasi
Maida Abbasi il 17 Nov 2015
Modificato: Walter Roberson il 17 Nov 2015
>> dbstop if error
??? Error using ==> vertcat
CAT arguments dimensions are not consistent.
Error in ==> dec2binvec at 45
out = logical(STR2NUM([fliplr(out);blanks(length(out))]')');
Error in ==> ReadBinFile at 15
bits_tmp = dec2binvec(outBytes')';
Error in ==> check at 6
code = ReadBinFile('check.txt.lz');
these are the errors i get
Walter Roberson
Walter Roberson il 17 Nov 2015
Shrug. I already told you what the problem was with this code. You did not listen then, so there is no reason to expect you would listen now.
Stephen23
Stephen23 il 17 Nov 2015

Accedi per commentare.

Tag

Richiesto:

il 16 Nov 2015

Commentato:

il 17 Nov 2015

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by