How to code a function that calculates the redundancy of a given alphabet
1 view (last 30 days)
Show older comments
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 Comments
KALYAN ACHARJYA
on 19 Nov 2020
Edited: KALYAN ACHARJYA
on 19 Nov 2020
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
Accepted Answer
KSSV
on 19 Nov 2020
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 Comments
More Answers (0)
See Also
Categories
Find more on Octave in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!