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

2 views (last 30 days)
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.

Answers (1)

Jan
Jan on 30 Dec 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))

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!