MATLAB Answers


Plotting a normalised histogram graph

Asked by John
on 21 Dec 2011

Hi there,

I've imported a column vector of 3000 'distances traveled' values.

I am hoping to plot a graph similar to this one

I'm only interested in plotting the blue bars

I'm fairly new to matlab, could somebody please advise me on how I would to this.

For the blue bars would I need to normalize the data first and then plot a histogram chart? What function would I use?

Many thanks



Log in to comment.

1 Answer

Answer by Junaid
on 21 Dec 2011
 Accepted Answer

Dear John,

Let say you have distance in D. You first have to take Histogram. For histogram if you know the number of bins then can give it as input or by default value will be applied. In given figure there are I assume 140 bins. So your code goes as follow:

h = hist(D,140); %D is your data and 140 is number of bins.
h = h/sum(h); % normalize to unit length. Sum of h now will be 1.
   bar(h, 'DisplayName', 'Travel Distance'); 

Do let me know If I answered your question correctly.


Dear Junaid,

Many thanks for your help. The code is perfect and I understand it.

dear junaid is it possible to normalize hsv histogram...

Log in to comment.

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!