How can I plot a histogram with specified axis
조회 수: 11 (최근 30일)
이전 댓글 표시
I have a row of data. For example [0 0.1 0.2 0.3 0.1 0.2]
I want to plot a histogram that have same number of bins with the number of data.
My final goal is that the histogram have 5 bins and 1st bin has value 0 2nd bin has value 0.1 and so on.
Thank you very much !
댓글 수: 0
답변 (1개)
Guillaume
2015년 12월 17일
편집: Guillaume
2015년 12월 17일
Use unique to get the sorted unique values of your array and use that as your bins. Note that due to the way histcounts / histogram work with the last bin you need to add an extra bin at the end ( +Inf works):
data = [0 0.1 0.2 0.3 0.1 0.2]
bins = [unique(data) Inf];
h = histcounts(data, bins)
Important: If your data has been generated by some mathematical calculations then there may be some very small differences between your first and second 0.1 that matlab by default does not show. However, unique won't consider them equal. If that is the case, use uniquetol instead. To see what I mean, compare:
>>data = [0.1+0.1+0.1 0.3]
data =
0.3 0.3
>>unique(data)
ans =
0.3 0.3
>>uniquetol(data)
ans =
0.3
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Histograms에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!