Hi all,
I'm trying to create a program to find a specific data value. I have a list of a bunch of numbers, and I want to find the first one after which there are four increasing numbers, then, in the next five numbers, no two decreases consecutively. Example: 1 2 3 4 5 6 5 6 7 would return 1. Mostly, my problem is handling the indices on this (getting it to shift one number down every time), and the different loops. Any help appreciated!

 採用された回答

Guillaume
Guillaume 2016 年 8 月 4 日

0 投票

This is how I would do it:
v = [1 2 3 2 1 2 3 4 5 4 3 1 2 3 4 5 4 5 1 2 3 4 5 6 5 6 ]; %sequence of interest is at index 12 (and 19 and 20)
sdv = sign(diff(v)); %find direction of change. 1 = increase, -1 = decrease, 0 = no change
increaseidx = strfind(sdv, [1 1 1 1]); %strfind also works for finding sequences of numbers
decreaseidx = strfind(sdv, [-1 -1]);
%we want indices that have increase but NO decrease 5 indices later
sequenceidx = increaseidx(~ismember(increaseidx+5, decreaseidx))
Certainly loops are not required

3 件のコメント

Maggy
Maggy 2016 年 8 月 4 日
Thanks for the answer! Is there a way to look at the five numbers after the first four, and make sure the decrease isn't at any point in them (not just at the end)? If I put (decreaseidx,increaseidx+5), problems start to happen.Thanks so much!
Guillaume
Guillaume 2016 年 8 月 4 日
sequenceidx = increaseidx(~any(ismember(increaseidx+5 : increaseidx+9, decreaseidx)))
should do the trick.
Maggy
Maggy 2016 年 8 月 4 日
THanks!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Matrix Indexing についてさらに検索

タグ

質問済み:

2016 年 8 月 4 日

コメント済み:

2016 年 8 月 4 日

Community Treasure Hunt

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

Start Hunting!

Translated by