Search All of the Math Forum:
Views expressed in these public forums are not endorsed by
Drexel University or The Math Forum.



Re: Collapse/Compress Longform Data
Posted:
Apr 29, 2013 3:54 PM


On Tuesday, April 30, 2013 7:39:09 AM UTC+12, Cory wrote: > Hi MATLABers, > > > > I have some data that can be put into groups of different sizes. For instances, I might have an nX2 vector where the first column is a group number and the second is a value: > > > > [1 2; 1 3; 1 1; 2 6; 2 10; 3 9; 3 11; 3 0] > > > > Is there an easy/fast/vectorized way to get MATLAB to take the minimum (maximum, sum, mean...) by group number? For the minimum, e.g, the result would be: > > > > [1 1; 2 6; 3 0] > > > > Obviously I could use loops, but I'm curious if there's a better solution. Thanks! > > > > Cory
Loop on group number, and calculate stats using vectorised code.



