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

1 次查看(过去 30 天)
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 中查找有关 Dictionaries 的更多信息

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by