Extracting groups from a matrix in MATLAB

1 view (last 30 days)
I have a csv output from a program that has three columns of interest, and they look like:
[1 1 0.1, 1 2 0.01, 1 3 0.4; 2 1 0.3, 2 2 0.2, 2 3 0.4; 3 1 0.5, 3 2 0.3, 3 3 0.5]
ans = 3×9
1.0000 1.0000 0.1000 1.0000 2.0000 0.0100 1.0000 3.0000 0.4000 2.0000 1.0000 0.3000 2.0000 2.0000 0.2000 2.0000 3.0000 0.4000 3.0000 1.0000 0.5000 3.0000 2.0000 0.3000 3.0000 3.0000 0.5000
I would like to group by the second column, as that is the object number, and then combine the other columns such that for object 1 you would have:
[1 0.1; 2 0.3; 3 0.5]
This would be listed as its own entity Object 1. The experiments that I do could have different frequency of data gathering, so the numbers of columns would vary, and I would like this to be dynamically done. Additionally, the second column, aka the object column may not have an entry for every time point (the first column), as the object may go in and out of view.
I have looked at several functions, and think that the correct function is "findgroup" but when I do findgroup(myMatrix) it returns the first column's time points, and when I try findgroup(myMatrix(:,2)) as to sort by the second column, it gives nonsensical numbers, and doesn't retain the other columns.
Thank you for your help!

Answers (0)

Products


Release

R2020a

Community Treasure Hunt

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

Start Hunting!