How to calculate the mean value of the non vero value in a vector?
조회 수: 1 (최근 30일)
이전 댓글 표시
How to calculate the mean value of the non vero value in a vector?
For example there is a vector contains 3 values M = [0.7,0.3,0]
the mean value in this case should be 0.5
댓글 수: 0
채택된 답변
추가 답변 (1개)
James Tursa
2022년 9월 3일
편집: James Tursa
2022년 9월 3일
Another way that doesn't require any data copying:
M = [0.7,0.3,0];
sum(M)/nnz(M)
Be aware that if there are no non-zero elements, this will return NaN (same as Star's method).
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Error Functions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!