How to calculate the entropy?
55 ビュー (過去 30 日間)
古いコメントを表示
How can I calculate the entropy of a sentence and selected sentence of a string. Thanks
採用された回答
Ameer Hamza
2020 年 4 月 24 日
Suppose you have a string
str = 'A quick brown fox';
1. If you have image processing toolbox, then try
ent = entropy(uint8(str))
2. Otherwise, you can also download this FEX submission: https://www.mathworks.com/matlabcentral/fileexchange/38295-compute-the-entropy-of-an-entered-text-string
ent = ComputeEntropy(str);
3. You can also write the following code which does not require any other toolbox
p = sum(str.'==unique(str))./length(str);
ent = -sum(p.*log2(p));
Same result for all three options
ent =
3.6901
13 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Statistics and Machine Learning Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!