How to add particular elements in a vector based on some condition in a loop fashion
1 view (last 30 days)
Show older comments
Raghavendra Reddy P
on 5 Feb 2015
Commented: Raghavendra Reddy P
on 5 Feb 2015
I have two vectors L and Z of length 'n' and 'n-1'. for ex:L=[L1 L2 -L3 L4 -L5 L6 L7 -L8 L9 L10] & Z=[Z1 Z2 Z3 Z4 Z5 Z6 Z7 Z8 Z9] starting from last element to first of vector L i.e L10, L9.... L1 if L is negative i.e first negative is -L8 add Z8+Z9 i.e elements between -L8 to end which are z8,z9 Look for next negative element of L i.e -L5 add Z5+Z6+Z7 i.e elements between -L5 and -L8 which are z6,z6,z7 look for next negative element of L i.e -L3 add Z3+Z4 i.e between -L3 and -L5 which are z3,z4 and finally add Z1+Z2 i.e between -L3 and starting point which are z1,z2...
this should continue in loop passion and finally my new vector(NV) should look like NV=[Z1+Z2, Z3+Z4, Z5+Z6+Z7,Z8+Z9]
Please do the needful thank you
0 Comments
Accepted Answer
More Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!