How could I cut a matrix into subgroups?

How could I cut a matrix into several small groups according to the 1st column, and I don't know how many subgroups I may get and the size of the subgroups are not the same(rows).
Say I have a matrix,
1 23 34
1 2 3
3 45 76
3 5 66
3 2 7
3 23 32
4 2 2
4 5 27
4 1 0 ....
And finally, I would like to get :
1 23 34
1 2 3
and
3 45 76
3 5 66
3 2 7
3 23 32
and
4 2 2
4 5 27
4 1 0
and ...
How could I do that? Thanks in advance!

 採用された回答

Sean de Wolski
Sean de Wolski 2011 年 6 月 9 日

0 投票

[sz] = histc(X(:,1),unique(X(:,1))); %X is your matrix
C = mat2cell(X,sz,size(X,2)) %each cell will contain one matrix
This is tuned to work assuming column one is sorted if it's not:
X = sortrows(X,1);

1 件のコメント

Zoe
Zoe 2011 年 6 月 9 日
Thank you so much!

サインインしてコメントする。

その他の回答 (1 件)

Matt Fig
Matt Fig 2011 年 6 月 9 日

0 投票

A = round(rand(10,4));
B = mat2cell(A,[2 3 4 1],[2 2])

1 件のコメント

Zoe
Zoe 2011 年 6 月 9 日
Thank you so much!

サインインしてコメントする。

カテゴリ

ヘルプ センター および File ExchangeSparse Matrices についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by