Calculation of conditional expectations
Show older comments
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 Comments
Greg
on 3 Jun 2018
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
on 3 Jun 2018
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
on 3 Jun 2018
Walter Roberson
on 3 Jun 2018
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.
Accepted Answer
More Answers (0)
Categories
Find more on Introduction to Installation and Licensing in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!