specifying bin increments on a histogram

조회 수: 4 (최근 30일)
John
John 2013년 1월 13일
Hello,
I use the code below to create a plots like this with different data sets. I want all plots to have the same scale, i.e. 0 to 90 and -2 to +2.
Not all data sets have data values at the extreme ends of the scales around 80-90 or 1.8-2 for example.
For example if the data in data set only ranges from 0-75 does the code divide the data up into bin intervals of 75/90 or does it create bins in 1 mph increments so bins 76-90 would have no data?
My question is, how can you specify that you want 90 bins a 1 mph increments and you want 40 bins at 0.1 increments from -2 to +2?
load Data;
% Calculate histogram
nBinsX = 120;
nBinsY = 40;
hist3(Data,[nBinsX,nBinsY]);
% Plot histogram
set(gcf,'renderer','opengl');
s = get(gca,'child');
zData = get(s,'zData');
colormap gray;
set(s,...
'zData' ,zData/length(Data),... % normalize frequency
'FaceColor' ,'interp',...
'EdgeColor' ,0.3*[1 1 1],... % make edges visible at all heights
'CDataMode' ,'auto'); % color tops according to height
% Labels
title('Velocity VS Acceleration Distribution');
xlabel('Velocity (mph)');
ylabel('Acceleration (m/s^2)');
zlabel('Normalized Frequency');

답변 (2개)

Walter Roberson
Walter Roberson 2013년 1월 13일
If you want specific bins, then pass in the list of bin centers if you are using hist(), or pass in the list of bin edges if you are using histc()
  댓글 수: 1
the cyclist
the cyclist 2013년 1월 13일
Note that John is using hist3(), which is just a bit different in syntax from hist() and histc().

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


the cyclist
the cyclist 2013년 1월 13일
I suggest you make a careful read of
>> doc hist3
There is a section near the top that describes exactly how to specify either the bin centers or edges that you want.
  댓글 수: 3
Jan
Jan 2013년 1월 14일
edges = {0:4, -2:0.1:-1.6}
John
John 2013년 1월 14일
Thanks

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

카테고리

Help CenterFile Exchange에서 Data Distribution Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by