Matlab Scripts for Huffman Encoding of text files

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
Walter Roberson 2011 年 2 月 25 日
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
Walter Roberson 2011 年 2 月 25 日
Have you considered using sort() instead of your nested loop to sort the values ?
Jan
Jan 2011 年 2 月 25 日
Do you have a question?

回答 (0 件)

この質問は閉じられています。

質問済み:

2011 年 2 月 25 日

閉鎖済み:

2023 年 1 月 9 日

Community Treasure Hunt

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

Start Hunting!

Translated by