Finding averages excluding a number
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentar
Image Analyst
am 22 Sep. 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
Akzeptierte Antwort
Walter Roberson
am 22 Sep. 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.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!