Split vector into increasing and decreasing

1 vue (au cours des 30 derniers jours)
ANKUR KUMAR
ANKUR KUMAR le 6 Déc 2017
Réponse apportée : Rik le 6 Déc 2017
How to split A vector as increasing and decreasing vectors. eg.
A=[1 1 2 2 3 3 8 9 4 3 2 2 2 1 0]
I want the output to be two vectors.
First should be the increasing one
[1 1 2 2 3 3 8 9]
Second should be the decreasing one
[4 3 2 2 2 1 0]
I have tried diff(), but the problem is with the repeating numbers which comes in between of increasing sequencce.

Réponses (1)

Rik
Rik le 6 Déc 2017
A=[1 1 2 2 3 3 8 9 4 3 2 2 2 1 0];
idx=find(diff(A)<0,1);%only get the first value
part1=A(1:idx);
part2=A((idx+1):end);

Catégories

En savoir plus sur MATLAB dans Help Center et File Exchange

Tags

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by