Error using hist function for entropy calculation

조회 수: 2 (최근 30일)
Dhani Dharmaprani
Dhani Dharmaprani 2017년 2월 17일
댓글: Dhani Dharmaprani 2017년 2월 17일
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.

채택된 답변

Walter Roberson
Walter Roberson 2017년 2월 17일
You have
nbins = logspace( 10, Nbinsizes, N / 10);
logspace(A, B, N) is equivalent to
10.^linspace(A, B, N)
so you are asking for 10.^(10, 5, 100)
The first entry of that is going to be 10^10 . And you are asking for that to be used as the number of bins in your hist() call.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Descriptive Statistics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by