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
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))
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 个评论
Ameer Hamza
Ameer Hamza 2020-5-5
Do you want to replace entropy value with zero width character?

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile 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!

Translated by