Calculation of conditional expectations
显示 更早的评论
Suppose I have a vector A and I would like to calculate the sum of the elements in A divided by the number of positive elements of A. Please advise.
6 个评论
Greg
2018-6-3
Sounds like the mean of A after you set all negative values of A to 0. What have you tried, and where are you stuck?
Walter Roberson
2018-6-3
No, if you set the negative values to 0 then the count of those 0 get included in the mean. Furthermore, the negative values are to be included in the sum even if the count is only to be for the positive values.
alpedhuez
2018-6-3
Walter Roberson
2018-6-3
That code assumes you have a row vector.
That code counts the number of non-zeros in the vector, instead of counting the number of positive values.
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Introduction to Installation and Licensing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!