How to omit zeros while using mean at varfun?

조회 수: 6 (최근 30일)
Kazi Alam
Kazi Alam 2021년 6월 10일
댓글: Kazi Alam 2021년 6월 10일
Hallo, Thanks for reading!
I want to know if this is posssible to omit zeros to calculate mean values using the following line of code?
varfun(@mean, data(indexrows,indexheaders), 'InputVariables', @isnumeric)

채택된 답변

Walter Roberson
Walter Roberson 2021년 6월 10일
편집: Walter Roberson 2021년 6월 10일
varfun(@(x)sum(x,1)./sum(x~=0,1), data(indexrows,indexheaders), 'InputVariables', @isnumeric)
This has been designed to be able to handle column-by-column non-zero mean for cases where a table variable might be a 2D array instead of a column vector.

추가 답변 (1개)

KSSV
KSSV 2021년 6월 10일
Convert zero's to NaN and use nanmean.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by