Plotting a normalised histogram graph

조회 수: 241 (최근 30일)
John
John 2011년 12월 21일
편집: Morteza Darvish Morshedi 2021년 3월 12일
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
John

채택된 답변

Junaid
Junaid 2011년 12월 21일
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');
legend('show');
Do let me know If I answered your question correctly.
  댓글 수: 2
John
John 2011년 12월 21일
Dear Junaid,
Many thanks for your help. The code is perfect and I understand it.
R
R 2013년 7월 15일
dear junaid is it possible to normalize hsv histogram...

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Morteza Darvish Morshedi
Morteza Darvish Morshedi 2021년 3월 12일
편집: Morteza Darvish Morshedi 2021년 3월 12일
In the recent versions of MATLAB:
% D is your data
% b can be number of bins, or edges
histogram(D,b, 'Normalization','probability');
You may want to have a look at the documentation here.

카테고리

Help CenterFile Exchange에서 Histograms에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by