Borrar filtros
Borrar filtros

Sum the component of a vector till a certain value

5 visualizaciones (últimos 30 días)
luca
luca el 31 de Ag. de 2019
Respondida: the cyclist el 31 de Ag. de 2019
Hi,
given the vector G= [2 4 4 5 6 16 8 9 21 3 5 8 12 34 5 6 8] I want to obtain a new vector S with the same component but cutted at the element X when the sum of each single elements exceed a specific value Y.
So if in our case Y=80. the new vector S would be
S = [2 4 4 5 6 16 8 9 21 3], in this case the sum of the elements reach 78.
Adding the element 5 we obtain 83, exceeding our limit. That's why we cut at the element X=3, obtaining S= [2 4 4 5 6 16 8 9 21 3].
Does someone know hot to implement this?

Respuesta aceptada

the cyclist
the cyclist el 31 de Ag. de 2019
G(cumsum(G)<80)

Más respuestas (0)

Categorías

Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.

Productos


Versión

R2019a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by