Filter löschen
Filter löschen

Strcat and HuffMan Word Code & GUI

1 Ansicht (letzte 30 Tage)
mohamed
mohamed am 20 Dez. 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 Kommentar
Walter Roberson
Walter Roberson am 21 Dez. 2012
Please show us your real code line that you represented here as
stri=strcat(stri,*My Problem In Here*)

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

mohamed
mohamed am 21 Dez. 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 Kommentar
Walter Roberson
Walter Roberson am 21 Dez. 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (4)

Walter Roberson
Walter Roberson am 21 Dez. 2012
Change
stri=strcat(stri,codewords(nn))
to
stri=strcat(stri,char('0' + codewords(nn)))

mohamed
mohamed am 21 Dez. 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 Kommentare
Walter Roberson
Walter Roberson am 21 Dez. 2012
stri=strcat(stri,char('0' + codewords{nn}))
mohamed
mohamed am 21 Dez. 2012
Bearbeitet: mohamed am 21 Dez. 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

Melden Sie sich an, um zu kommentieren.


mohamed
mohamed am 21 Dez. 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 am 21 Dez. 2012
thank you so much Walter you really helped me alot :)

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by