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

1 回表示 (過去 30 日間)
Leesy
Leesy 2017 年 2 月 22 日
コメント済み: Leesy 2017 年 2 月 22 日
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!

採用された回答

Adam
Adam 2017 年 2 月 22 日
編集済み: Adam 2017 年 2 月 22 日
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).

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by