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

조회 수: 1 (최근 30일)
Koustubh Shirke
Koustubh Shirke 2020년 12월 29일
답변: Jan 2020년 12월 30일
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.

답변 (1개)

Jan
Jan 2020년 12월 30일
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))

카테고리

Help CenterFile Exchange에서 Get Started with MATLAB에 대해 자세히 알아보기

제품


릴리스

R2020a

Community Treasure Hunt

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

Start Hunting!

Translated by