Histogram shows one value at the very end that ruins the plot
조회 수: 1 (최근 30일)
이전 댓글 표시
Hello I have a vactor of values and I am ploting a histogram. I get one value at the very end that is ruining my plot. I cannot get rid of this. Can you please help.
My code is simple and is below. I have also attached data file RT160 in .mat format. Please help.
figure(1);
histogram(RT160,150);
xlabel('Cost (USD)');
ylabel('Counts');
댓글 수: 1
답변 (1개)
Steven Lord
2022년 3월 9일
If that last bin is (roughly) twice as high as you think it should be, that's because the last bin includes both values that match its left bin edge and values that match its right bin edge. The rest of the bins include just their left bin edge (leaving their right bin edge to their neighbor to the right.)
x = randi(10, 1, 1e3);
figure
histogram(x, 1:10) % Last bin contains both 9 and 10
figure
histogram(x, 1:11) % Last bin is [10, 11] which matches only 10 in x
I'd just add one element at the end of my bin edges, the max of my data plus my desired BinWidth.
desiredBinWidth = 1;
newUpperLimit = max(x) + desiredBinWidth
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Data Distribution Plots에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!