Why do I receive an error when using HIST with integer data types?

1 vue (au cours des 30 derniers jours)
The HIST function does not appear to work with integer data types in MATLAB 7.2 (R2006a). I enter the following code at the MATLAB Command Prompt:
y = uint8(10*rand(1000,1));
hist(y)
I receive the error message:
??? Error using ==> mtimes
Integers can only be combined with integers of the same class, or scalar doubles.
Error in ==> hist at 73
xx = miny + binwidth*(0:x);
I would like to create a histogram from UINT8, UINT16, and UINT32 data.

Réponse acceptée

MathWorks Support Team
MathWorks Support Team le 7 Jan 2010
This change has been incorporated into the documentation in Release 2009b (R2009b). For previous releases, read below for any additional information:
This is expected behavior for the HIST function in MATLAB. It is designed to work with single and double data types. You may instead wish to use the function IMHIST in Image Processing Toolbox which can handle a larger range of integer data types.
To create a histogram in MATLAB from integer data with HIST, you will need to manually specify integer bin centers. For example,
y = uint8(10*rand(1000,1));
hist(y,0:10)
You may also typecast your integer data using the DOUBLE function:
hist(double(y));
Note that if you typecast, the bin centers will not always be integers; this may distort your data.

Plus de réponses (0)

Catégories

En savoir plus sur Numeric Types dans Help Center et File Exchange

Produits


Version

R2006a

Community Treasure Hunt

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

Start Hunting!

Translated by