How to find where the differences between elements is constant?

So let's say these are my values:
x y
0 29
0 30
0 30
16760 30
16760 31
16760 31
16760 31
16760 31
16760 31
16760 32
16760 32
16760 32
16760 32
16760 33
16760 32
16760 33
16760 33
16760 33
16760 33
16760 33
16760 34
16760 34
16760 33
18330 34
18330 33
18330 35
19130 35
19130 35
what i need to know is for the periods that x is constant, the values of y (in my problem y is actually speed so i need the values to integrate and find distance afterwards)
so i would like to have as a result something like for x1=16760,y=30 31 31 31 31 31 32 32 32 32 33 32 33 33 33 33 33 34 34 33
x2=18330, y=34 33 35
x3=19130, y=35 35
etc..
Is that possible? any suggestion is welcome! thank you!

 Accepted Answer

xy = [0 29
0 30
0 30
16760 30
16760 31
16760 31
16760 31
16760 31
16760 31
16760 32
16760 32
16760 32
16760 32
16760 33
16760 32
16760 33
16760 33
16760 33
16760 33
16760 33
16760 34
16760 34
16760 33
18330 34
18330 33
18330 35
19130 35
19130 35];
[a,~,c] = unique(xy(:,1));
out = [num2cell(a), accumarray(c,xy(:,2),[],@(x){x})];

More Answers (0)

Categories

Tags

Asked:

on 22 May 2014

Commented:

on 22 May 2014

Community Treasure Hunt

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

Start Hunting!