For example If I have a matrix like this

x = [ 2.356 37

1.351 39

4.394 37

3.622 39

4.489 39

3.135 37

6.653 39 ]

I want to sum up the values that are specific to 37 and 39 seperatly only if it is alternative. If 39 and 37 are not alternative like in 4th and 5 th row wants to add that to the next subsecuent value in this case it is 37.

Some of the 37 should be (2.356+4.394+4.489+3.135), 39 should be (1.351+3.622+6.653). Please help in getting a matlab code for this!

Thank you in advance

## Best Answer