Sorting out data in a matrix

1 回表示 (過去 30 日間)
AJA
AJA 2020 年 12 月 5 日
編集済み: Rik 2020 年 12 月 6 日
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 日
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.

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by