How to get back the dictionary to input into huffmanndeco function?

조회 수: 2 (최근 30일)
Derick Wong
Derick Wong 2014년 1월 10일
답변: Walter Roberson 2014년 1월 11일
I used the huffmandict function to get the dictionary and used the huffmanenco function with the dictionary matrix passed in to get the encoded compressed output. I then appended the encoded output and the dictionary value into a file. A snapshot of the file is shown below
Now, i need to get back the dictionary matrix from the file to pass in to huffmandeco function. How should i go about getting back the dictionary matrix from the file? I tried using loop to get the value and assigned to cell matrix but when i passed in the generated dictionary matrix, the huffmandeco throw error saying the dictionary matrix is not correct. Btw, "." refers to a new row while "," refers to the next column.
Below are the printout for the dictionary generated from huffmandict function (dict double) and the dictionary matrix generated from the file (DecompDict character).
dict =
[-47] [1x10 double]
[-17] [1x10 double]
[ -7] [1x9 double]
[ -3] [1x7 double]
[ -2] [1x4 double]
[ -1] [1x2 double]
[ 0] [ 1]
[ 1] [1x3 double]
[ 2] [1x5 double]
[ 3] [1x6 double]
[ 7] [1x9 double]
[ 17] [1x10 double]
[ 30] [1x10 double]
DecompDict =
'-47' '[0,0,1,0,1,0,1,0,0,1]'
'-17' '[0,0,1,0,1,0,1,0,0,0]'
'-7' '[0,0,1,0,1,0,1,1,1]'
'-3' '[0,0,1,0,1,0,0]'
'-2' '[0,0,1,1]'
'-1' '[0,1]'
'0' '1'
'1' '[0,0,0]'
'2' '[0,0,1,0,0]'
'3' '[0,0,1,0,1,1]'
'7' '[0,0,1,0,1,0,1,1,0]'
'17' '[0,0,1,0,1,0,1,0,1,1]'
'30' '[0,0,1,0,1,0,1,0,1,0]'
Thank you.
  댓글 수: 1
Walter Roberson
Walter Roberson 2014년 1월 11일
Why are you using "." to separate columns and "," to separate rows? Why not use "," for columns and ";" for rows? Or "," to seperate columns and {} around the components for each row, thus emulating the way one might store in a cell array ?

댓글을 달려면 로그인하십시오.

답변 (1개)

Walter Roberson
Walter Roberson 2014년 1월 11일
regexp(TextString, ',', 'split')
Then you can use regexp to process each cell string result. I do not have MATLAB installed on the system I am writing this on, so I cannot test for an efficient way to break it out.

카테고리

Help CenterFile Exchange에서 Source Coding에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by