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 中查找有关 NaNs 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!