필터 지우기
필터 지우기

Same bins for histogram

조회 수: 62 (최근 30일)
Kash Costello
Kash Costello 2019년 1월 7일
댓글: Rik 2020년 6월 15일
Hi,
I have this code - attached in this post.
When you run this program, it would give you several subplots with histogram in some of them.
The thing is, I want to make the bins the same for all the histograms. I put "10" but the widths are still different.
I have no idea how to fix is, I am very confused. I also attached one image, just in case.
I want the widths to be the same for columns 2 and 3.
Thanks a lot!

답변 (2개)

Rik
Rik 2019년 1월 7일
What you are telling Matlab is to divide the range [min(data) max(data)] in 10 equal parts. Because your data has differing ranges, these sizes are different as well.
You can fix this by calculating appropriate bins yourself, and use those as an argument in the calls to histogram.
  댓글 수: 3
Benoit Espinola
Benoit Espinola 2020년 6월 15일
I do not think this comment solved the question. I believe it is a step forward however the solution is not evident. It arises yet another question: how do you calculate the bins yourself?
An example code would be great.
Rik
Rik 2020년 6월 15일
I believe it actually is evident once you take a look at the documentation. What exact bins are relevant will depend on your application. The documentation contains an example for how you can specify the bin edges. When you have decided what bin ranges are suited for your application you can use those same edges for every histogram. You may want to round min(data) and max(data) to determine those outer limits automatically, instead of hard-coding them as I did below.
% since the data in this example ranges from about -20 to 80:
edges=lispace(-20,80,20);
subplot(1,2,1)
histogram(data1,edges)
subplot(1,2,2)
histogram(data2,edges)

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


Image Analyst
Image Analyst 2019년 1월 14일
Instead of passing in one number, that represents the number of bins, pass in an array for the 'edges' option. This is how you can specify the edges, or dividing lines, of the bins. You'll still have the same number of bins, but the location of the bins will not move around based on the data like they would if you passed just the number of bins.

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by