Info
此问题已关闭。 请重新打开它进行编辑或回答。
Matlab Scripts for Huffman Encoding of text files
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Walter Roberson
2011-2-25
Have you considered using sort() instead of your nested loop to sort the values ?
回答(0 个)
此问题已关闭。
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!