How to take average/median of table columns without the zeros?
조회 수: 1 (최근 30일)
이전 댓글 표시
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
채택된 답변
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 Exchange에서 Statistics and Machine Learning Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!