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

1 visualizzazione (ultimi 30 giorni)
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.

Risposte (1)

Jan
Jan il 30 Dic 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))

Categorie

Scopri di più su Get Started with MATLAB in Help Center e File Exchange

Prodotti


Release

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by