Strcat and HuffMan Word Code & GUI

조회 수: 1 (최근 30일)
mohamed
mohamed 2012년 12월 20일
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
Walter Roberson
Walter Roberson 2012년 12월 21일
Please show us your real code line that you represented here as
stri=strcat(stri,*My Problem In Here*)

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

채택된 답변

mohamed
mohamed 2012년 12월 21일
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
Walter Roberson
Walter Roberson 2012년 12월 21일
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.

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

추가 답변 (4개)

Walter Roberson
Walter Roberson 2012년 12월 21일
Change
stri=strcat(stri,codewords(nn))
to
stri=strcat(stri,char('0' + codewords(nn)))

mohamed
mohamed 2012년 12월 21일
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
Walter Roberson
Walter Roberson 2012년 12월 21일
stri=strcat(stri,char('0' + codewords{nn}))
mohamed
mohamed 2012년 12월 21일
편집: mohamed 2012년 12월 21일
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

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


mohamed
mohamed 2012년 12월 21일
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 2012년 12월 21일
thank you so much Walter you really helped me alot :)
  댓글 수: 1
Walter Roberson
Walter Roberson 2012년 12월 21일
Vote early. Vote often.

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

카테고리

Help CenterFile Exchange에서 Large Files and Big Data에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by