Error using hist function for entropy calculation

1 回表示 (過去 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.
  1 件のコメント
Dhani Dharmaprani
Dhani Dharmaprani 2017 年 2 月 17 日
Thank you so much for that, that makes sense!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by