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!

 채택된 답변

Sean de Wolski
Sean de Wolski 2016년 2월 2일

6 개 추천

댓글 수: 3

Thank you!
histogram(S,'Normalization','probability')
This gave me exactly what I needed!
Sajid Afaque
Sajid Afaque 2020년 6월 12일
@Sean de Wolski i am having the same issue but since i am using 2013b version the above syntax is not valid. do you have any idea of doing same using hist.
Owen Tolfrey
Owen Tolfrey 2020년 12월 18일
[N,edges] = histcounts(y,'Normalization','probability');

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

추가 답변 (2개)

mayank awasthi
mayank awasthi 2018년 8월 7일

1 개 추천

if we want to find the area under this histogram then how can we do that?

댓글 수: 1

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
george veropoulos 2020년 9월 24일

0 개 추천

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

sadegh sehhat
sadegh sehhat 2022년 1월 4일
편집: sadegh sehhat 2022년 1월 4일
insted of that you can use this code
if fn is your data set:
histogram(fn,nbins,'Normalization','pdf')

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

카테고리

도움말 센터File Exchange에서 Histograms에 대해 자세히 알아보기

질문:

2016년 2월 2일

편집:

2022년 1월 4일

Community Treasure Hunt

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

Start Hunting!

Translated by