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!