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
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
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 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Data Workflows 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!