Conditional mean for a matrix (calculate the mean ignoring the negative numbers)
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Daniel Maniov
am 19 Dez. 2019
Beantwortet: Allen
am 19 Dez. 2019
I have a matrix m x n with positive (including zeros) and some negative numbers.
How can I calculate the mean of all the numbers ignoring the negatives?
For example, my matrix is:
-1 2 4
3 -1 5
-1 3 4
This "conditional mean" should calculate (2+4+3+5+3+4)/6 = 3.5
Thanks.
0 Kommentare
Akzeptierte Antwort
Allen
am 19 Dez. 2019
Use something similar to the below example
A = [-1, 2, 4
3,-1, 5
-1, 3, 4];
mean(A(A>=0))
0 Kommentare
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!