Problem with the mean function

Hi everyone,
I've got a little pb with the 'mean' function :
My matrix has a class 'double' on my workspace : &lt70080*1 double> I would like to do an average of those values :
moyenne = mean(refoulement(1:8760,1)) and the answer is NaN. The values are positives.
Do you have an idea ?
Thanks !

 Respuesta aceptada

Kye Taylor
Kye Taylor el 2 de Mayo de 2012

0 votos

Try this
meanWithoutNans = mean(refoulement(~isnan(refoulement)));

2 comentarios

Alexandre
Alexandre el 2 de Mayo de 2012
Ok it works perfectly. If i want to select some rows in my matrix, where should I put it ?
Here for ex : meanWithoutNans = mean(refoulement(~isnan(refoulement(1:i,:)))); ?
Ty
Kye Taylor
Kye Taylor el 2 de Mayo de 2012
I interpret you question as, "How do I take the mean of rows in a matrix and avoid the nans?"
To do that, try
meanOfRowsWithoutNans = zeros(size(refoulement,1),1);
for i = 1:size(refoulement,1) % for each row
meanOfRowsWithoutNans(i) = ...
mean(refoulement(i,~isnan(refoulement(i,:))));
end

Iniciar sesión para comentar.

Más respuestas (3)

Image Analyst
Image Analyst el 2 de Mayo de 2012

0 votos

What does this say:
hasNans = max(isnan(refoulement))
I want to see if there are any nan's in your original matrix.
Alexandre
Alexandre el 2 de Mayo de 2012

0 votos

The answer for hasNans = max(isnan(refoulement)) is one thus I guess there are some NaN in the column.
What should I do then ?
I saw some topic explaining that in that case I have to code a function to get rid of the NaN, is that correct ?
Unfortunately, I don't have that toolbox.
Thanks for your help !

Categorías

Productos

Etiquetas

Preguntada:

el 2 de Mayo de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by