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

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by preet
on 13 Mar 2013

a=[2,14,23,12,4,4,10,1]

if there is any value in the array a() is less than or equal to 15 than that will add to next value of same array and store in the another array b(). each value in b() should be more than 15 at last if there is no value in the array a() and the addition is less than equal to 15 then the result of addition will add to the previous value to the array b().

a=[2,14,23,12,4,4,10,1];

index=1;i=1;

while (i<=8)

if(a(i)>15)

b(index)=a(i); index=index+1; else value=a(i); j=i; while(value<=15) if(j<8) j=j+1; value=value+a(j); % j=j+1; else break; end end i=j+1; if(value>15)

b(index)=value; index=index+1; else b(index)=b(index)+value; end end end

and my answer after to implment it. infinite loop going on. my answer should be b=[31,23,16]

*No products are associated with this question.*

## 6 Comments

## Jan Simon

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/66975#comment_136223

@kpreet: Would it bother, if anybody else post answers also?

But what should be answered, when there is no question? Does the posted code solve your problem? If not, what happens instead?

## preet

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/66975#comment_136236

sir any one can answer my question..

## Walter Roberson

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/66975#comment_136269

You did not post a question.

## Cedric Wannaz

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/66975#comment_136655

I don't get how you aggregate

a..The

bthat you provide seems to be the outcome ofand I don't understand why the reverse order. Also, I could propose

which would match the criterion

b(i) > 15. Can you provide more information about the logic behind the way you aggregated your solution?## preet

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/66975#comment_136659

if a=[1,14,23,12,4,4,10,1]

then [15, 35,16] so should i add 15+35 or 15+16?

## Cedric Wannaz

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/66975#comment_136703

>>

so should i add 15+35 or 15+16?Well, it is up to

youto perfectly know/define what you want to compute and how. Then we can help you writing MATLAB code (or improving it) for that.