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

New to MATLAB?

Thread Subject:
Is there any method similar to group by as in Access SQL

Subject: Is there any method similar to group by as in Access SQL

From: Shiguo

Date: 24 Jan, 2009 23:12:02

Message: 1 of 1

I have a matrix, the first column is the ID, representing fractories. The other columns are attributes of the fractories, for example, product and there quantities. However, the matrix is organized as follows:
ID product quantity
1 p1 10
2 p2 20
2 p3 30
3 p1 50
4 p2 60
So there are duplicate ID. I want to re-organize this table to this:
ID p1 p2 p3
1 10 0 0
2 0 20 30
3 50 0 0
4 0 60 0

First, I want to create a m*2 matrix bgID, where m is the size of ID, here bgID(:,1)=1:4. bgID(:,2) is stores the number of duplicates for each ID, here bgID(:,2) =[1, 2, 1, 1]'.
In Access SQL, we can create a query using the following way to get the to get result:

select ID, count(*) as IDCount
group by ID

Is there any way to get this in matlab? Thanks.

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