MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by Sam Stuart
on 7 May 2013

How can I sum one column based on the data in another column:

1 8 2 8 3 8 4 4 5 5 6 8 7 8 8 8 9 7

I have a column with numbers 1-8, and a column with just numbers in.

I want to add/sum the numbers in column 1 whenever the second column is less than 8. I need to only add the rows that are consecutive to each other.

Anyone got any ideas?

*No products are associated with this question.*

## 3 Comments

## Sean de Wolski (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/74917#comment_147775

This looks like it will be fun once you post a full example. Please provide

allinputs and a sample output with an explanation of how you got it.## the cyclist (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/74917#comment_147779

I agree with Sean that a bit more detail (and a small example) would help. I thought I knew what you meant, until you said "only add the rows that are consecutive to each other".

Try to put yourself in our place, trying to understand what you want to do, given

onlyyour description.## Jan Simon (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/74917#comment_147786

I've formatted the numbers and suddenly 2 columns appear instead of onw row. I cannot imagine, why the OP did not care about the formatting. Perhaps he can explain, which part of the instructions is too hard to understand, such that TMW can improve it.