Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Collapse/Compress Long-form Data
Replies: 2   Last Post: Apr 29, 2013 3:58 PM

 Messages: [ Previous | Next ]
 Derek Goring Posts: 3,922 Registered: 12/7/04
Re: Collapse/Compress Long-form 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.

Date Subject Author
4/29/13 Cory
4/29/13 Derek Goring
4/29/13 Cory