MATLAB: Sum of elements in an array over x

arraycriteriacumulativeelementssum

Hello all,
I am looking to find the sum of elements in an array which exceed a certain value, e.g. 0.05.
I have this array: [0.023 0.056 0.053 0.034 0.021 0.075 0.088]
As you can see, 4 elements are over 0.05. However, I don't want to know 'how many elements' are over 0.05, I want to find the cumulative sum of the elements which match my criteria.
In this case: 0.056 + 0.053 + 0.075 + 0.088.
Total = 0.272
Can anyone help?
kind regards,
Jacob

Best Answer

a = [0.023 0.056 0.053 0.034 0.021 0.075 0.088];
result = sum(a(a>0.05))