Matlab – How to plot a histogram in MATLAB


I have one vector (newdata) consisting of 4100 lines and one column. To be exact, those elements are the counts of a spectrum. What I want is to reproduce the spectrum using MATLAB. That's why I created a new vector:


I tried to plot the spectrum (using channel in x axis and newdata as a weight) by typing:


But I got an error

??? Error using ==> histc
Edges vector must be monotonically non-decreasing.

Error in ==> hist at 86
    nn = histc(y,[-inf bins],1);

How can I draw the desired spectrum?

Best Solution

try plotting using the bar command

bar( channels, newData );