MATLAB: Hist() function: Error using .* Error in hist (line 78)

histMATLABmatlab 2013bwinxp 32bit

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 "512×512 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 "262144×1 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.

Best Answer

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