Matlab Scripts for Huffman Encoding of text files
Infos
Cette question est clôturée. Rouvrir pour modifier ou répondre.
Afficher commentaires plus anciens
Dear all, I need a Matlab script for the Huffman Encoding of text files not from a text input(file name input) but from (character,probability) input . here is the code.
clc; clear all; k=input('Enter the file name :','s'); fid = fopen(k,'r'); F = fread(fid); img = char(F'); mx=255; [x y z]=size(img); h(1:mx)=0; disp('Histogram building phase started....'); for i=1:y iy=img(i); val=double(iy); h(val)=h(val)+1; end end disp('Probability calculating phase started...'); i=1:mx p(i)=h(i)/(x*y); j=1; for i=1:mx if(p(i)~=0) lst(j)=i; lst(j+1)=p(i); j=j+2; end [tt,mx]=size(lst); disp('sorting phase started....'); for i=2:2:mx for j=i:2:mx if (lst(i)>lst(j)) temp1=lst(i-1); temp2=lst(i); lst(i-1)=lst(j-1); lst(i)=lst(j); lst(j-1)=temp1; lst(j)=temp2; end end end disp('Building Huffman Tree.....'); fhtree1(lst,img);
thanks
3 commentaires
Walter Roberson
le 25 Fév 2011
Please reformat your code to be readable. If you edit and select the text and press the "code" button, then it will come out nicely.
Walter Roberson
le 25 Fév 2011
Have you considered using sort() instead of your nested loop to sort the values ?
Jan
le 25 Fév 2011
Do you have a question?
Réponses (0)
Cette question est clôturée.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!