How to take average/median of table columns without the zeros?
1 view (last 30 days)
Show older comments
Hey there, I have a big table (called pm2d), 12 columns by 31 rows, and i need to take the average and median of each column without the zeros being factored in. I know i can use for loop and if statement to check the number of valid data points and get a new array with only valid data points... But every code i try to write is not working. Any assistance would be appreciated! Thanks!
0 Comments
Accepted Answer
Adam
on 22 Feb 2017
Edited: Adam
on 22 Feb 2017
pm2d( a ) ./ sum( logical( pm2d ) );
will give you the mean without taking zeros into account.
If you have a recent version of Matlab then
pm2d( pm2d == 0 ) = NaN;
medianRes = median( pm2d, 'omitnan' );
will give the median (you can actually do the same thing with 'mean' too).
More Answers (0)
See Also
Categories
Find more on Statistics and Machine Learning Toolbox 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!