Anomalous histogram for small argument

2 ビュー (過去 30 日間)
Gordon Edwards
Gordon Edwards 2019 年 9 月 6 日
コメント済み: Gordon Edwards 2019 年 9 月 7 日
Running the following code from the command line with c = 1e-15 or greater leads to a normal histogram
c = 1e-15; figure; histogram(c * rand(100,1))
histogram1.JPG
Running the following code with c = 1e-16 or less leads to an incorrect histogram
c = 1e-16; figure; histogram(c * rand(100,1))
histogram2.JPG
The problem appears also in apps when the histogram function is invoked.
Is this a bug?
Gordon

採用された回答

Bruno Luong
Bruno Luong 2019 年 9 月 7 日
編集済み: Bruno Luong 2019 年 9 月 7 日
Yes it is a BUG. I chase back and in the file
C:\Program Files\MATLAB\R2019a\toolbox\matlab\datafun\+matlab\+internal\+math\binpicker.m
line #20 (R2019a)
there is a test
if xrange > max(sqrt(eps(xscale)), realmin(class(xscale)))
To me the correct test should be (without sqrt)
if xrange > max(eps(xscale), realmin(class(xscale)))
Now if I change this line and rerun the code
c = 1e-16; figure; histogram(c * rand(100,1))
it produces correct plot
More seriously, the function binpicker is called by HISTCOUNT. So HISTCOUNT is also buggy. Not only plotting but calculation might be wrong.
  1 件のコメント
Gordon Edwards
Gordon Edwards 2019 年 9 月 7 日
Thanks for your reply.and I believe that you have spotted the error in function binpicker.Since eps(x) ~ 1e-16*x, and in my case xscale and xrange are nearly equal, the condition that
xrange > sqrt(eps(xscale))
leads to xrange >~ 1e-16 which is what I find.

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

その他の回答 (1 件)

Jackson Burns
Jackson Burns 2019 年 9 月 7 日
Here's a similar question asked a few years ago which was never really solved either. This comment may be your best approach, but I would reccomend just bringing the values to unity with something like this:
c = 1E-16;
figure
mydata = c * rand(100,1);
histogram(mydata./max(mydata))
You could then modify the xticklabels to match whatever the original values were.

カテゴリ

Help Center および File ExchangeData Distribution Plots についてさらに検索

製品


リリース

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by