how to remove a bar from histogram which drawn using 'hist' function?
10 views (last 30 days)
Show older comments
hi can anyone help me to remove zeros bar in histogram this is a part of the code . i'm new in matlab so pleas help me
[hCount, hValues] = hist(h(:), 6);
[sCount, sValues] = hist(s(:), 6);
[vCount, vValues] = hist(v(:), 6);
% Plot histograms.
subplot(3, 4, 6);
bar(hValues, hCount);
title('Hue Histogram');
subplot(3, 4, 7);
bar(sValues, sCount);
title('Saturation Histogram');
subplot(3, 4, 8);
bar(vValues, vCount);
title('Value Histogram');
0 Comments
Accepted Answer
Tom Lane
on 22 Feb 2013
If you want to omit zeros from the bar calculations:
hist(h(h~=0), 6)
Depending on your data, this may omit the bar that contains zero.
If you want to omit bars that have zero height, well, when I try this I don't see anything at those spots. Maybe you could explain some more.
0 Comments
More Answers (1)
Image Analyst
on 22 Feb 2013
Sometimes your counts have one bar that you want to get rid of, for example the bar for the v bin representing a v value of 0 is so tall that when you display it you can't see the other bars because they're so short. To do that, I typically just set that counts value to zero before plotting.
[vCount, vValues] = hist(v(:), 6);
% Let's say the first bin is way, way taller than the other bins
% so you can't see the shape of the histogram of the other bins.
% You can set the bin = 0
vCount(1) = 0;
% Then plot it
bar(vValues, vCount, 'BarWidth', 1.0);
Alternatively you can take the log of the counts to compress the tall bins:
bar(vValues, log(vCount), 'BarWidth', 1.0);
0 Comments
See Also
Categories
Find more on Histograms in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!