How to add particular elements in a vector based on some condition in a loop fashion
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Raghavendra Reddy P
el 5 de Feb. de 2015
Comentada: Raghavendra Reddy P
el 5 de Feb. de 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 comentarios
Respuesta aceptada
Más respuestas (0)
Ver también
Categorías
Más información sobre Loops and Conditional Statements en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!