Finding averages excluding a number
5 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Hi,
I'm having a bit of trouble finding the average value of a matrix. Its a 1000x10 matrix, and I want to find the average of each column, only I don't want to include a certain number (say 99 for example). So I want to find the average of each column excluding any cell which contains the number 99. for example, say column 1 is as follows: 5 5 99 10 I want to exclude 99 so that the average comes out at 6.67 Could anyone help me? Thank you!
1 comentario
Image Analyst
el 22 de Sept. de 2011
I hope that's an integer array, otherwise you should be aware of the FAQ: http://matlab.wikia.com/wiki/FAQ#Why_is_0.3_-_0.2_-_0.1_.28or_similar.29_not_equal_to_zero.3F
Respuesta aceptada
Walter Roberson
el 22 de Sept. de 2011
exclude = 99;
numexcluded = sum(X == exclude);
colavgs = (sum(X) - numexcluded * exclude) ./ (size(X,1) - numexcluded);
Note: this code will not work if the value to be excluded is NaN or one of the infinities.
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!