Extracting groups from a matrix in MATLAB
1 view (last 30 days)
Show older comments
Nicholas Scott on 28 Feb 2022
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]
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!
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!Start Hunting!