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

3 ビュー (過去 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 Center および File ExchangeHistograms についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by