hist() function: Error using .* Error in hist (line 78)
1 次查看(过去 30 天)
显示 更早的评论
When trying to generate with the HIST function a histogram I get an error message and do not know what I have to modify in my simple data analysis approach in order to prevent this. The error message is:
Error using .*
Integers can only be combined with integers of the same class, or scalar doubles.
Error in hist (line 78)
xx = miny + binwidth*(0:x);
I load a TIF image into MATLAB 2013b (not having the Image Processing Toolbox, simply the MATLAB ore program, WinXP 32 bit) and receive the myimage variable of type "512x512x3 uint8"
myimage = imread(filename);
Trying to show a histogram produces the error message:
hist(myimage)
I then separated individual color channels to the variables R, G, and B, which result of type "512x512 uint8":
R= myimage(:,:,1);
G= myimage(:,:,2);
B= myimage(:,:,3);
Trying to show the histogram for one of these variables also produces the error message:
hist(R)
I tried to resample the content of a variable into a vector of type "262144x1 uint8", but still receive the same error message
test=R(:); hist(test)
Sorting then didn´t help neither:
test=sort(test); hist(test)
Neither worked finally changing the type of the variable:
test=int16(test); hist(test)
test=int8(test); hist(test)
What do I have to do, please, in order to get a histogram of the values of a color channel drawn, and especially, where am I not using the hist() function correctly? I am pretty sure that I do not completely understand what the error message wants to hint me to.
0 个评论
采纳的回答
Kevin Claytor
2013-10-30
It seems as though hist() prefers floating point values (single or double). Try;
hist(double(R(:))) % Histogram of red channel
Also, note that hist operates column-wise;
hist(double(R)) % column-wise histogram
更多回答(1 个)
Image Analyst
2013-10-30
If you have the Image Processing Toolbox, use imhist(). But you can only use it on one color channel at a time.
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!