How to calculate the entropy?

조회 수: 43 (최근 30일)
Balkar Singh
Balkar Singh 2020년 4월 24일
댓글: Balkar Singh 2020년 5월 5일
How can I calculate the entropy of a sentence and selected sentence of a string. Thanks
  댓글 수: 1
darova
darova 2020년 4월 24일
Where is MATLAB?

댓글을 달려면 로그인하십시오.

채택된 답변

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?
Balkar Singh
Balkar Singh 2020년 5월 5일
yes to make it invisible

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by