Strcat and HuffMan Word Code & GUI

1 view (last 30 days)
mohamed
mohamed on 20 Dec 2012
Hello everyone,
i have a problem with applying something on matlab which is:
for nn=1:a
stri=character(nn);
stri=strcat(stri,':');
stri=strcat(stri,num2str(probabilities(nn)));
stri=strcat(stri,':')
stri=strcat(stri,*My Problem In Here*)
stri=strcat(stri,':');
end
what i want to do is after getting the probability for each alpha and numebers and the spaces and the codeword i want to put them beside each other.
For example:
A:0.342:001100
D:0.432:011011
and so on.....
but when im trying to do that everytime its give me
A:0.342:' '
D:0.432:' '
without the codeword
what i have to do im kinda lost and i have to handout this project after tomorrow :S
thank you....
if there is any more information please ask! :)
  1 Comment
Walter Roberson
Walter Roberson on 21 Dec 2012
Please show us your real code line that you represented here as
stri=strcat(stri,*My Problem In Here*)

Sign in to comment.

Accepted Answer

mohamed
mohamed on 21 Dec 2012
im done now with the GUI is there a way to put :
for nn=1:a
stri=character(nn);
stri=strcat(stri,':');
stri=strcat(stri,num2str(probabilities(nn)));
stri=strcat(stri,':')
stri=strcat(stri,num2str(codewords{nn}(length(codewords{nn}):-1:1)))
stri=strcat(stri,':');
end
i dont want it to be in the same place where the rest of the output i want to be alone with another window like when i use pushbottom i want it to open another window written on it:
A:0.342:001100
D:0.432:011011
K:0.244:10010
  1 Comment
Walter Roberson
Walter Roberson on 21 Dec 2012
You can use figure() to open a new window. In that new figure, create a uicontrol() of 'Style', 'edit', and 'Enable', 'disabled', and set its 'String' property to the text you want.

Sign in to comment.

More Answers (4)

Walter Roberson
Walter Roberson on 21 Dec 2012
Change
stri=strcat(stri,codewords(nn))
to
stri=strcat(stri,char('0' + codewords(nn)))

mohamed
mohamed on 21 Dec 2012
when i changed it, its giving me this error:
??? Undefined function or method 'plus' for input arguments of type 'cell'.
Error in ==> HuffMan at 101
stri=strcat(stri,char('0' + codewords(nn)))
  2 Comments
Walter Roberson
Walter Roberson on 21 Dec 2012
stri=strcat(stri,char('0' + codewords{nn}))
mohamed
mohamed on 21 Dec 2012
Edited: mohamed on 21 Dec 2012
its working but its kinda flip the answer i don't know if its right to do that or its something wrong see what i mean :
The symbols, their probabilities and the allocated Huffman codewords are:
1 0.032258 1 0 1 0 0
2 0.064516 0 0 1 1
3 0.16129 1 1 1
4 0.096774 0 0 0
5 0.12903 0 1 0
6 0.032258 1 0 1 0 1
7 0.064516 0 1 1 0
8 0.032258 1 0 1 1 0
9 0.064516 0 1 1 1
10 0.064516 1 0 0 0
11 0.032258 1 0 1 1 1
12 0.032258 1 1 0 0 0
13 0.032258 1 1 0 0 1
14 0.032258 1 1 0 1 0
15 0.032258 1 1 0 1 1
16 0.064516 1 0 0 1
17 0.032258 0 0 1 0
stri =
H:0.032258:00101
stri =
e:0.064516:1100
stri =
l:0.16129:111
stri =
o:0.096774:000
stri =
:0.12903:010
stri =
I:0.032258:10101
stri =
m:0.064516:0110
stri =
M:0.032258:01101
stri =
h:0.064516:1110
stri =
a:0.064516:0001
stri =
d:0.032258:11101
stri =
K:0.032258:00011
stri =
i:0.032258:10011
stri =
A:0.032258:01011
stri =
b:0.032258:11011
stri =
u:0.064516:1001
stri =
z:0.032258:0100

Sign in to comment.


mohamed
mohamed on 21 Dec 2012
look what i did
i change the old one with this
stri=strcat(stri,num2str(codewords{nn}(length(codewords{nn}):-1:1)))
its giving me this :
-------------------------------------------------------------------------
The symbols, their probabilities and the allocated Huffman codewords are:
1 0.032258 1 0 1 0 0
2 0.064516 0 0 1 1
3 0.16129 1 1 1
4 0.096774 0 0 0
5 0.12903 0 1 0
6 0.032258 1 0 1 0 1
7 0.064516 0 1 1 0
8 0.032258 1 0 1 1 0
9 0.064516 0 1 1 1
10 0.064516 1 0 0 0
11 0.032258 1 0 1 1 1
12 0.032258 1 1 0 0 0
13 0.032258 1 1 0 0 1
14 0.032258 1 1 0 1 0
15 0.032258 1 1 0 1 1
16 0.064516 1 0 0 1
17 0.032258 0 0 1 0
av_length =
3.8710
entropy =
3.8457
efficiency =
0.9935
stri =
H:0.032258:1 0 1 0 0
stri =
e:0.064516:0 0 1 1
stri =
l:0.16129:1 1 1
stri =
o:0.096774:0 0 0
stri =
:0.12903:0 1 0
stri =
I:0.032258:1 0 1 0 1
stri =
m:0.064516:0 1 1 0
stri =
M:0.032258:1 0 1 1 0
stri =
h:0.064516:0 1 1 1
stri =
a:0.064516:1 0 0 0
stri =
d:0.032258:1 0 1 1 1
stri =
K:0.032258:1 1 0 0 0
stri =
i:0.032258:1 1 0 0 1
stri =
A:0.032258:1 1 0 1 0
stri =
b:0.032258:1 1 0 1 1
stri =
u:0.064516:1 0 0 1
stri =
z:0.032258:0 0 1 0
what do u think? is it right like this or it should flip like u send me?

mohamed
mohamed on 21 Dec 2012
thank you so much Walter you really helped me alot :)

Categories

Find more on Large Files and Big Data in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!