How Can I fix the width of Bins?

조회 수: 4 (최근 30일)
reyadh Albarakat
reyadh Albarakat 2015년 5월 30일
댓글: Walter Roberson 2015년 5월 30일
Hi Every body, I would like to tell you that I am beginner in Matlab. So please I need your help.
I want to fix the width of bins of the histogram, My code is:
% cd F:\Script\Center_Marsh\Center_Marsh_1992
H= Dec_1992(:);
hist(H);
subplot(1,2,1)
hist(H)
xlabel('NDVI','fontsize',14)
ylabel('AVHRR Pixels','fontsize',14)
set(gca,'XMinorTick','on')
set(gca,'YMinorTick','on')
set(gca,'XGrid','on')
set(gca,'YGrid','on')
set(gca,'GridLineStyle',':','linewidth',1)
set(gca,'TickDir','out')
set(gca,'TickLength',[.015 .025])
axis([0.0 0.5 0 110])
save('Dec_Hist_1992.fig');
D= Dec_1992(:);
[hi,cx]=hist(D);
subplot(1,2,2), plot(cx, hi,'k', 'LineWidth', 3)
xlabel('NDVI','fontsize',14)
ylabel('AVHRR Pixels','fontsize',14)
set(gca,'XMinorTick','on')
set(gca,'YMinorTick','on')
set(gca,'XGrid','on')
set(gca,'YGrid','on')
set(gca,'GridLineStyle',':','linewidth',1)
set(gca,'TickDir','out')
set(gca,'TickLength',[.015 .025])
axis([0.0 0.5 0 110])
save('Dec_Hist_1992.fig');
Thank you
Reyadh
  댓글 수: 4
reyadh Albarakat
reyadh Albarakat 2015년 5월 30일
I would like to Fix the Number of Bin and its Width with the whole data.
Thank you
Reyadh
Walter Roberson
Walter Roberson 2015년 5월 30일
If you fix the number of bins and you also fix the bin width, then it might not be possible to fit all of the data. Even in cases where it is possible, you have ambiguity.
Imagine that the requested bin width is 2 and imagine that there is 1 point to be covered. Possible coverings include
|x |
| x |
| x|
The bin width was fixed, the number of bins was fixed, but the policy was not fixed.
Why does it matter? Because of fairness. Consider 2 bins of fixed width, and 4 points.
| xx x| x | -> centered but uneven distribution
| xx |x x | -> not centered but equal distribution
| x|x x x| -> not centered, unequal
There are techniques to dynamically move the boundaries to get the most even distribution (defined by lowest sum of squares of number of elements in each bin), but for a simple histogram you place your boundaries first and then you count once, not knowing ahead of time how the points distribute. So basically you start with the information about where the first point is and where the last point is; and you have forced the number of bins and the bin widths; and now you need a policy about where to put the bin centers to distribute the mod((max-min),bin_width) extra space.

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

답변 (1개)

Star Strider
Star Strider 2015년 5월 30일
I would use hist to calculate the histogram information, then use bar to do the plot, since it will let you vary the width of the bars.
  댓글 수: 2
reyadh Albarakat
reyadh Albarakat 2015년 5월 30일
Hi Star Strider, How can I use that with my code. I am beginner in matlab.
Thank you
Reyadh
Star Strider
Star Strider 2015년 5월 30일
My pleasure.
I actually thought you intended bar width, since it is easy to set the bins in the hist function or its friends.
To get the histogram data to use with the bar plot, request it as an output from hist. See the documentation for Use hist to Calculate Only. (I see that in your code, but the documentation shows how to use it with bar.)
To set the bar width for the entire bar plot, see the documentation for Specify Bar Width.

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

카테고리

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