Error using hist function for entropy calculation
Ältere Kommentare anzeigen
Hi,
I am currently trying to write a function to calculate the Shannon entropy of some data, however, am getting the following error:
Requested 10000000001x1 (74.5GB) array exceeds maximum array size preference. Creation of arrays greater than this limit may take a long time and cause MATLAB to become unresponsive. See array size limit or preference panel for more information. Error in linspace (line 33) y = d1 + (0:n1).*(d2 - d1)./n1; Error in hist (line 96) edges = linspace(miny,maxy,x+1);||||_
The code I have currently is as follows:
N = 1000;
D = 10;
Nbinsizes = 5;
% create a random white noise signal
x = randn( 1, N);
nbins = logspace( 10, Nbinsizes, N / 10);
Histogram_Shannon_Entropy = nan( 1, Nbinsizes);
for i = 1:Nbinsizes
p = hist( x, nbins( i))/N;
Histogram_Shannon_Entropy( i) = sum( -( p( p > 0) .* ( log2( p ( p > 0)))));
end
I'm struggling to understand what the cause of this error is, so any help is greatly appreciated! Thank you kindly in advance.
Akzeptierte Antwort
Weitere Antworten (0)
Kategorien
Mehr zu Descriptive Statistics finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!