Conditional mean for a matrix (calculate the mean ignoring the negative numbers)
조회 수: 10 (최근 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!