Sorting out data in a matrix

For example, I have a 100 x 3 matrix A
A = [1 0 542
1 5 21
1 10 125
1 15 6245
1 20 2678
1 50 580
1 55 1205
1 60 196
2 0 5129
2 5 34
2 10 248
2 15 348
2 20 583
2 25 480
… … ...]
where, column 1 is object
column 2 is movement number
column 3 is the point of the object
Movement is determined by the spacing of the values in column 2, if the spacing is more than 5 it will be categorized as a new move. When lookin at the second column, starting at 0, 5, 10, 15 up to 20 all has a space of 5 and is considered to be 1 movement. The space between 20 and 50 is not 5, so 50 is not included in that movement and will be recorded as the start of a new movement. So for 1 movement of ID 1, the starting point is at 0 and the ending point is at 15. For movement 2 of ID 1, starting point is 580 and end point is 196. I want to determine how many movements each object ID has done. Also, the data in the 3rd column needs to be recorded at the start and end of a move.
The output matrix should look like this:
B = [1 1 542 2678
1 2 580 196
2 1 5129 480]
where, column 1 is object ID
column 2 is movement number
column 3 is starting point of movement
column 4 is endpoint of movement

댓글 수: 1

Rik
Rik 2020년 12월 6일
Why did you edit away large parts of your question? I will restore it from Google cache. Removing your question like this is extremely rude.
If something isn't working, post a comment.

댓글을 달려면 로그인하십시오.

답변 (1개)

Rik
Rik 2020년 12월 5일

0 개 추천

Loop through the elements of find(diff(A(:,3))>=5)
That way you can get the row indices for the cases you need. That should make it easy to create B.

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

태그

질문:

AJA
2020년 12월 5일

편집:

Rik
2020년 12월 6일

Community Treasure Hunt

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

Start Hunting!

Translated by