Can we remove a bar from histogram which drawn using 'hist' function?
2 次查看(过去 30 天)
显示 更早的评论
Hi, I have a data and i tried to calculate mean and standard deviation for that data values. where lots of zeros are there and i don't need to include that zeros for my data range. my data range is in Matrix.
I need to calculate mean and standard deviation only for data except zero values. Please help on this problem.
3 个评论
Image Analyst
2012-11-20
I think he has a huge bar for the "zero" bin and he wants to suppress that bar because it makes all the other bars so short. He can either set the "counts" value to zero for that bin, or just avoid seeing any zeros in the first place when he calculates the histogram, like you suggested.
回答(1 个)
José-Luis
2012-11-20
idx = your_data ~=0;
You can now calculate the mean and standard deviation:
your_mean = mean(data(idx));
your_std = mean(data(idx));
3 个评论
José-Luis
2012-11-20
It would appear so
x=rand(100000,1) > 0.5;
tic
mean(x(x~=0));
toc
tic
sum(x)/(length(x)-sum(x == 0));
toc
Elapsed time is 0.002031 seconds.
Elapsed time is 0.000810 seconds.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Histograms 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!