Find number of consecutive elements before value changes (MATLAB) -


I have one (line) vector of some size, which has values ​​of 1,2 and 3. They are not there 'specific' order, then there will be a specimen of the array [1,1,1,1,2,2,2,1,1,2,2,3,3] What do I want to do, similar elements Continuous number of matches, but with some restrictions.

What I need is to create new arrays, in which elements are represented:

  • <2> Before it changes to 1, the number of consecutive 2
  • The number of consecutive 2 changes to 3 before
  • 3 consecutive numbers before it turns into 2

Example I have given, arrays

  [4], 2] [3] [2] []  

I'm not sure how to deal with this . I can use the difference, where this signal changes, but then it will know what has really changed, okay?

The method is not super fast, because I only have to do some time for 10 ^ 5 datapoint.

This approach will be the way you specify in the question:

  a = [1,1,1,1,2,2,2,1,1,2,2,3,3] b = Diff (a) c = find (b) d = diff ([0 , C]); Type 1 = D (B (C) == 1 & amp; A (C) == 1); Type 2 = D (B (C) == -1 and A (C) == 2); Type 3 = D (B (C) == 1 & amp; A (C) == 2); Type 4 = D (B (C) == -1 and A (C) == 3); Type 1 = 4 2 type 2 = 3 type 3 = 2 type 4 = empty matrix: 1-B-0  

Comments

Popular posts from this blog

import - Python ImportError: No module named wmi -

Editing Python Class in Shell and SQLAlchemy -

c# - MySQL Parameterized Select Query joining tables issue -