필터 지우기
필터 지우기

How to fit a long tail in histogram in one bin?

조회 수: 5 (최근 30일)
Iro
Iro 2013년 6월 5일
Hi,
I have a vector X with some time values in sec. I want to make a histogram of its distribution, but since it has a long tail it is really hard for one to perceive the scale. My vector X has values from 0 to 16000 sec, but I would like the hist to be printed until the value of 2010 (with interval of 30sec) and the rest observations to be stored all together as >2010 or something equivalent. The code I use so far is:
xint=30; % my interval
edges=(30-xint:xint:2010); % 30*67=2010
[n,bin]=histc(X,edges);
n1=0;
for i=1:size(X,2)
if Χ(i)>xint*67 % only right tail
n1=n1+1
end
end
n(end)=n(end)+n1;
figure
bar(edges,n,'histc')
but what I get is not what I want to get, since the bars are not connected to each other and by counting them it is like the observations of every other interval are missing...
Any suggestion?
Thanks,
Iro

채택된 답변

Mark
Mark 2013년 6월 5일
You could loop through your X values and make a temporary XT that assigns everything large to 2010:
XT=X;
XT(XT>xint*67) = xint*67;
[n,bin]=histc(XT,edges);
bar, etc.
  댓글 수: 2
Iro
Iro 2013년 6월 5일
Hi Mark,
thanks for your answer, but this does exactly what I was doing, but in a much more compact way. The problem is that the histogram is not what I want... there is some problem with the intervals, i set them equal to 30 sec but when I see the hist it is like either they are of 60sec or half of them are missing...
Mark
Mark 2013년 6월 5일
Not sure why. Are you sure your data has values in all the bins? When I generate some random data, and run it through the code, it looks like it has 67 bins with the extras in the last slot:
X = abs(randn(1,1000)*1000+300);
xint=30; % my interval
edges=(30-xint:xint:2010); % 30*67=2010
XT=X;
XT(XT>xint*67) = xint*67;
[n,bin]=histc(XT,edges);
figure
bar(edges,n,'histc')

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

추가 답변 (0개)

카테고리

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