MATLAB: Calculation of conditional expectations

MATLAB

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.

Best Answer

sum(A)./nnz(A>=0)