Plotting a normalised histogram graph
249 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
John
le 21 Déc 2011
Modifié(e) : Morteza Darvish Morshedi
le 12 Mar 2021
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
0 commentaires
Réponse acceptée
Junaid
le 21 Déc 2011
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 commentaires
Plus de réponses (1)
Morteza Darvish Morshedi
le 12 Mar 2021
Modifié(e) : Morteza Darvish Morshedi
le 12 Mar 2021
In the recent versions of MATLAB:
% D is your data
% b can be number of bins, or edges
histogram(D,b, 'Normalization','probability');
0 commentaires
Voir également
Catégories
En savoir plus sur Histograms dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!