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

1 Ansicht (letzte 30 Tage)
Koustubh Shirke
Koustubh Shirke am 29 Dez. 2020
Beantwortet: Jan am 30 Dez. 2020
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.

Antworten (1)

Jan
Jan am 30 Dez. 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))

Kategorien

Mehr zu Get Started with MATLAB finden Sie in Help Center und File Exchange

Produkte


Version

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by