How to normalize a histogram?
Mostrar comentarios más antiguos
I am having an incredible amount of difficulty in finding a direct answer to this question. I have an array S that is 300x1. Using histogram(S) I obtain the following histogram:

This histogram is exactly what I need except for one problem. I want this to be a relative frequency histogram. As in, I want the y-axis values to be a percentage of the total number of data points (300). For example, the bin between 0.5 and 0.6 is approximately 73, so I would want it to read as (73/300) or 0.243.
I have seen many answers to this type of question telling users to use the hist function and then create a bar graph. I do not want a bar graph. I want the x-axis to remain unchanged as the actual data values, NOT as bin numbers. Can anyone help? Thanks!
Respuesta aceptada
Más respuestas (2)
mayank awasthi
el 7 de Ag. de 2018
1 voto
if we want to find the area under this histogram then how can we do that?
1 comentario
Moritz Flor
el 21 de Sept. de 2018
Extract the bin values from the histogram, add them and multiply them by the bin width:
%%create histogram
x = randn(1000,1);
nbins = 25;
h = histogram(x,nbins)
%%extract parameters
counts = h.Values;
sum_counts = sum(counts);
width = h.BinWidth;
%%area of the histogram
area = sum_counts*width;
george veropoulos
el 24 de Sept. de 2020
0 votos
hi
i want to normalized the histogram
i use the hist
[f x]=hist(fn,nbins);
dx = diff(x(1:2));
bar(x,f./(sum(f.*dx)));
how i can use the histogram
thank you
1 comentario
sadegh sehhat
el 4 de En. de 2022
Editada: sadegh sehhat
el 4 de En. de 2022
insted of that you can use this code
if fn is your data set:
histogram(fn,nbins,'Normalization','pdf')
Categorías
Más información sobre Histograms en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!