How can I run through an array and pick out certain values by condition

1 vue (au cours des 30 derniers jours)
Yinka Badmus
Yinka Badmus le 16 Déc 2019
Modifié(e) : Yinka Badmus le 18 Déc 2019
I have an array (let's call it events) of 19372x1. In this array there are values that are just one number above the previous value. I want to loop through this array and whenever there are values with only a difference of 1 between them I want to pick out the value right at the center of this "sub-array". For example, if my array was [690 691 692 693 694 678 679 701 713] then I want to have a result of [692 678 701 713]. How can I implement this in MATLAB?

Réponses (1)

dpb
dpb le 16 Déc 2019
Start by finding locations of ix=[false diff(events)==1)] then locate the discontinuities in those stretches. Then it's the median of the subsections. Since you'll be shortening the vector, you'll have to be careful to either work from the end forward on substitutions or build a new result in order to not change positions just found.
  1 commentaire
Yinka Badmus
Yinka Badmus le 17 Déc 2019
Modifié(e) : Yinka Badmus le 18 Déc 2019
So how would I create these subsections to find the median?

Connectez-vous pour commenter.

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by