How to capture the increasing values patch(sub-vector) in matlab scripting ?

1 visualización (últimos 30 días)
Hi ,
In Matlab, I have a vector of values (positive as well as negative). Its contunious data.
By using matlab programming, how can I capture/find the slots/sub vectors where there is positive rise in values ?
for example, I have vector A = [1 1 1 0 -1 2 3 6 7 00123]. In this vector I want to capture sub-vector [-1 2 3 6 7] and [ 0 1 2 3]. If I would get its indexes, that will be better.
Thanks in Advance.

Respuestas (1)

Jan
Jan el 30 de Dic. de 2020
A = [1 1 1 0 -1 2 3 6 7 0 0 1 2 3];
D = [false, diff(A) > 0, false];
starting = strfind(D, [false, true])
ending = strfind(D, [true, false])
Now the blocks of growing data start at the indices stored in starting, and the end at ending:
A(starting(1):ending(1))

Categorías

Más información sobre Get Started with MATLAB en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by