How to omit zeros while using mean at varfun?

7 visualizaciones (últimos 30 días)
Kazi Alam
Kazi Alam el 10 de Jun. de 2021
Comentada: Kazi Alam el 10 de Jun. de 2021
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)

Respuesta aceptada

Walter Roberson
Walter Roberson el 10 de Jun. de 2021
Editada: Walter Roberson el 10 de Jun. de 2021
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.

Más respuestas (1)

KSSV
KSSV el 10 de Jun. de 2021
Convert zero's to NaN and use nanmean.

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

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

Start Hunting!

Translated by