Can we remove a bar from histogram which drawn using 'hist' function?

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

José-Luis
José-Luis 2012년 11월 20일
편집: José-Luis 2012년 11월 20일
Your actual question has nothing to do with your header, as far as I can see.
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.
Comprehension dawned upon me. Thanks.

댓글을 달려면 로그인하십시오.

답변 (1개)

José-Luis
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

I wonder if sum(x)/(length(x)-sum(x == 0)) would be faster for the mean.
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.
I will have to think about how to do the same thing for std.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Histograms에 대해 자세히 알아보기

질문:

2012년 11월 20일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by