How to code a function that calculates the redundancy of a given alphabet

2 次查看(过去 30 天)
I have a function that calculates the entropy of vector element
function h = alph_entropy(P)
h = -sum(P .* log2(P));
endfunction
What should i do next? Thanks!
Redundancy of entropy function should use alph_entropy function
  2 个评论
KALYAN ACHARJYA
KALYAN ACHARJYA 2020-11-19
编辑:KALYAN ACHARJYA 2020-11-19
Save the function in diffenent MATLAB script as function file, later call the same in main script. Vary P and get different results of h, later plot(P,h);
You may learn Basics from MATLAB Onramp

请先登录,再进行评论。

采纳的回答

KSSV
KSSV 2020-11-19
It looks like you are using Octave.
You can call functions in multiple ways.
Option 1:
function h = alph_entropy(P)
h = -sum(P .* log2(P));
end
Save the above function in a file and name it as alph_entropy.m. MATLAB takes the name default funciton name, but Octave you have to give the name. The name of the function and file name should be same. Then go to the folder where function is present and you can call this function in a file or in command window.
P = rand(100,1) ; % your P variable
h = alph_entropy(P) ; % calling function with P as input
Option 2: Annoymous function
h = @(P) -sum(P .* log2(P)) ; % this is a function handle
P = rand(100,1) ;
iwant = h(P)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Image Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by