MATLAB: Is the histogram with the hist function giving multiple colored lines

colorhisthistogramlinesMATLABmultiple

I am trying to create a histogram of my 100×10 matrix using the "hist" function and it is coming out with unexpected results with multiple colored lines. Why is this happening and how do I fix it?

Best Answer

It is recommended to use the "histogram" function instead of the "hist" function.
The "hist" function creates a histogram for each column of an input matrix and plots the histograms side-by-side in the same figure. This is why there are 10 colored lines for the 10 columns. The "histogram" function will treat the input matrix as a single tall vector and creates a single histogram.
For more information on the two functions and their differences, please see the following links: