How to code a function that calculates the redundancy of a given alphabet
1 Ansicht (letzte 30 Tage)
Ältere Kommentare anzeigen
Vadim Potorocha
am 19 Nov. 2020
Beantwortet: KSSV
am 19 Nov. 2020
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 Kommentare
KALYAN ACHARJYA
am 19 Nov. 2020
Bearbeitet: KALYAN ACHARJYA
am 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
Akzeptierte Antwort
KSSV
am 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Octave finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!