How to take average/median of table columns without the zeros?

1 visualización (últimos 30 días)
Leesy
Leesy el 22 de Feb. de 2017
Comentada: Leesy el 22 de Feb. de 2017
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!

Respuesta aceptada

Adam
Adam el 22 de Feb. de 2017
Editada: Adam el 22 de Feb. de 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).

Más respuestas (0)

Categorías

Más información sobre Statistics and Machine Learning Toolbox en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by