getting the mean EXCEPT zero entries

I have a matrix, M = [zeros(10,10); 1 , 2 , 3 ,4 ,5,6,7,8,9,10];
I want to get the mean of each column, except the zero terms. How do I do this?

Respuestas (1)

Fangjun Jiang
Fangjun Jiang el 9 de Nov. de 2018
M=zeros(5);
M(randi(25,10,1))=1:10;
M(M==0)=nan;
mean(M,'omitnan')

Categorías

Etiquetas

Preguntada:

cgo
el 9 de Nov. de 2018

Comentada:

el 9 de Nov. de 2018

Community Treasure Hunt

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

Start Hunting!

Translated by