Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Collapse/Compress Long-form Data

Subject: Collapse/Compress Long-form Data

From: Cory

Date: 29 Apr, 2013 19:39:09

Message: 1 of 3

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

Subject: Collapse/Compress Long-form Data

From: TideMan

Date: 29 Apr, 2013 19:54:02

Message: 2 of 3

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.

Subject: Collapse/Compress Long-form Data

From: Cory

Date: 29 Apr, 2013 19:58:09

Message: 3 of 3

> Loop on group number, and calculate stats using vectorised code.

Sure. But there's no 100% vectorized code? Or at least not code that's worth writing?

Tags for this Thread

No tags are associated with this thread.

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us