Calculating an average in an n x m array that contain zeros

12 views (last 30 days)
How can i calculate an average in an array where data in the columns are zero values and I don't want the zero to be considered when computig an average.
For example: A= [2 2 ; 2 4; 1 0] >>> mean(A) results in 1.667 2 >>>the answer I want is 1.667 3
Any assistance is much appreciated.

Accepted Answer

Matt Fig
Matt Fig on 2 Mar 2011
mn = sum(A)./sum(A~=0)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!