1sem matlab 05
This commit is contained in:
parent
41d0b979d1
commit
018bac4688
5 changed files with 110 additions and 0 deletions
25
1sem/octave/05/calc_info.m
Normal file
25
1sem/octave/05/calc_info.m
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
function [b,n] = calc_info(msg, alph, alph_p)
|
||||
l_alph = length(alph);
|
||||
l_alph_p = length(alph_p);
|
||||
l_msg = length(msg);
|
||||
if l_alph ~= l_alph_p;
|
||||
error("[ERR] length(alph) != length(alph_p) (%d != %d)", l_alph, l_alph_p)
|
||||
endif
|
||||
|
||||
b = 0;
|
||||
for i = 1:l_msg
|
||||
flag = false;
|
||||
for j = 1:l_alph
|
||||
if msg(i) == alph(j)
|
||||
flag = true;
|
||||
b -= log(alph_p(j));
|
||||
break
|
||||
endif
|
||||
endfor
|
||||
if ~flag
|
||||
warning("[WARN] Symbol '%s' (at pos. %d from msg) not found in alphabet", msg(i), i)
|
||||
endif
|
||||
endfor
|
||||
|
||||
n = l_msg * log2(l_alph);
|
||||
endfunction
|
||||
Loading…
Add table
Add a link
Reference in a new issue