unshow unnecessary intervalls in a histogramm
조회 수: 1 (최근 30일)
이전 댓글 표시
Hallo
I have a histogramm where i want to show only the values for certain intervalls.
the other intervalls i dont need and i dont want them to be shown.
thanks for any tip
댓글 수: 0
채택된 답변
Steven Lord
2021년 7월 22일
x = randn(1, 1e5);
h = histogram(x);
C = h.BinCounts;
E = h.BinEdges;
C([30:40 50 60]) = 0;
figure
histogram('BinCounts', C, 'BinEdges', E)
If you don't want to plot both histograms you could use histcounts to compute C and E instead of calling histogram.
댓글 수: 0
추가 답변 (1개)
Constantino Carlos Reyes-Aldasoro
2021년 7월 22일
Hello:
What you need to do is rather simple if you capture the values of your histogram, instead of using hist to display directly, For example take the data to be 500 Gaussian randomly distributed points. Take the histogram and save the values in x,y and then display:
data= randn(500,1);
[y,x]=hist(data,[-4:0.2:4]);
bar(x,y)
This is the equivalent of what you currently have, now you want to discard some of the bins produced, first let's see the size of x (and y would be the same):
numBins = numel(x)
So we know that it has 41 values, now, create a vector with those values that you want to keep and remove those you do not want, say you want to remove 11,21,22,23,24:
selected_bins=[1:10 12:20 25:numBins];
bar(x(selected_bins),y(selected_bins))
And that's it, you have a histogram with only the values you had selected.
Hope this solves your question. If yes, please accept the answer, if not, let me know.
댓글 수: 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!