Histogram bug in Matlab 2017a

8 vues (au cours des 30 derniers jours)
Alberto
Alberto le 13 Fév 2018
Modifié(e) : Alberto le 13 Fév 2018
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.

Réponses (2)

Steven Lord
Steven Lord le 13 Fév 2018
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.

Alberto
Alberto le 13 Fév 2018
To set the BinEdges I use
histogram('BinEdges', X{1}, 'BinCounts', X{2})
where X is a
1×2 cell array
{57×1 double} {58×1 double}
Thank you for pointing out the release note for histogram. It is indeed the cause of the different behavior.

Community Treasure Hunt

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

Start Hunting!

Translated by