Matlab – How to plot a histogram in MATLAB

histogrammatlabplot

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:

channels=[1:size(newdata,1)];

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

hist(channels,newdata)

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 );