How to calculate the entropy?

55 visualizaciones (últimos 30 días)
Balkar Singh
Balkar Singh el 24 de Abr. de 2020
Comentada: Balkar Singh el 5 de Mayo de 2020
How can I calculate the entropy of a sentence and selected sentence of a string. Thanks

Respuesta aceptada

Ameer Hamza
Ameer Hamza el 24 de Abr. de 2020
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 comentarios
Ameer Hamza
Ameer Hamza el 5 de Mayo de 2020
Do you want to replace entropy value with zero width character?
Balkar Singh
Balkar Singh el 5 de Mayo de 2020
yes to make it invisible

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Statistics and Machine Learning Toolbox en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by