implementing huffmandeco without using the inbuilt function
Afficher commentaires plus anciens
Basically I am trying to write the source code behind MATLAB's inbuilt function huffmandeco. This is what I have:
function dsig = myhuffmandeco(c,dict) % comp must be a numeric vector (row or col)
dsig = [];
[~, n] = size(c);
dictSize = size(dict,1);
function [tmpCodeSize,symbol] = getSymbol(code)
symbol=[];
%iterate through dictionary
for j = 1:dictSize
tmpCode = cell2mat(dict(j,2)); %tmpCode will contain the encoded words of the dictionary's (which is a cellArray) 2nd column
tmpCodeSize = size(tmpCode, 2);
codeSize = size(code, 2); %code is the current word in vector c I'm trying to decode
if tmpCodeSize > codeSize
break;
end
if isequal(codeSize,tmpCodeSize) && isequal(tmpCode,code)
symbol = cell2mat(dict(j,1)); %'symbol' will take the value of the dictionary's symbol that corresponds to the 'code'
break;
end
end
end
beginning = 1;
ending = 1;
while ending < n
[tmpCodeSize,symbol] = getSymbol(c(beginning:ending));
dsig =[dsig symbol];
if ending ~= n
beginning = ending;
ending = ending + tmpCodeSize;
end
end
end
Unfortunately, I get nothing as an output. I really can't tell if the problem lies in one of my iterations or the printing of it.. Any help is appreciated!
Réponses (0)
Catégories
En savoir plus sur Source Coding dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!