Histogram bug in Matlab 2017a
8 ビュー (過去 30 日間)
古いコメントを表示
I encountered an error using the command Histogram in Matlab 2017a:
Error using matlab.graphics.chart.primitive.Histogram
Expected BinEdges to be of size 1x58, but it is of size 58x1.
In Matlab 2016b the command was working fine whether the BinEdgses vector was a row or not. Is it possible to fix this bug without having to change all the code in my scripts?
EDIT: I also just found out that the normalization (e.g., 'pdf', 'probability') gives different results in 2016b vs. 2017a (see for example the attached screenshot: 2016b on the left, 2017a on the right)

EDIT 2: I think I found the error. I dug into the histcount code. The 2017a version is
if ~isempty(opts)
switch opts.Normalization
case 'countdensity'
n = n./double(diff(edges));
case 'cumcount'
n = cumsum(n);
case 'probability'
n = n / numel(x);
case 'pdf'
n = n/numel(x)./double(diff(edges));
case 'cdf'
n = cumsum(n / numel(x));
end
end
In the 2016b is
if ~isempty(opts)
switch opts.Normalization
case 'countdensity'
n = n./double(diff(edges));
case 'cumcount'
n = cumsum(n);
case 'probability'
n = n / sum(n);
case 'pdf'
n = n/sum(x)./double(diff(edges));
case 'cdf'
n = cumsum(n / sum(m));
end
end
where n is the bin count, and x is the input data. The difference is that in 2017a they used numel(n) as normalization factor, whereas in 2016b they used sum(n). Hence, if a bin does not contain any data (n = 0), numel will miscount the number of observations.
0 件のコメント
回答 (2 件)
Steven Lord
2018 年 2 月 13 日
Can you show the command you're using to try to set the BinEdges to a column vector? Are you doing that when you construct the histogram or are you trying to update the BinEdges after the histogram has been constructed?
Regarding Normalization, there was a change made to that option in release R2017a that may be responsible for the difference you observe. See the Release Notes for a description of the change and why it was made along with a link to the documentation page that shows how to achieve the older behavior.
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Histograms についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!