Conditional mean for a matrix (calculate the mean ignoring the negative numbers)
5 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Allen
2019 年 12 月 19 日
Use something similar to the below example
A = [-1, 2, 4
3,-1, 5
-1, 3, 4];
mean(A(A>=0))
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!