function E = entropy(d) d=strsplit(d); n=unique(string(d)); N=size(d,'r'); count=zeros(n); n_size = size(n,'r'); for i = 1:n_size count(i) = sum ( d == n(i) ); end E=0; for i=1:length(count) E = E - count(i)/N * log(count(i)/N) / log(2); end endfunction word ='1223334444'; E = entropy(word); disp('The entropy of '+word+' is '+string(E)+'.');