Sorting out data in a matrix

1 Ansicht (letzte 30 Tage)
AJA
AJA am 5 Dez. 2020
Bearbeitet: Rik am 6 Dez. 2020
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 Kommentar
Rik
Rik am 6 Dez. 2020
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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Rik
Rik am 5 Dez. 2020
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.

Kategorien

Mehr zu Shifting and Sorting Matrices finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by