To group the matrix based on the number on their column (of non-zeros)

2 次查看(过去 30 天)
I have a matrix below;-
Matr =
0 0
0 0
1 0
0 0
2 0
0 1
1 1
0 1
How can I group them based on their number of cloumn? Starts from 1st row to 7th row
I want the result to be....
group1=[3 1 %they are in the 1st row
5 1
7 1]
group2= [6 2
7 2] %they are in the 2nd row

采纳的回答

Guillaume
Guillaume 2018-11-28
[row, column] = find(Matr);
groups = splitapply(@(rows, columns) {[rows, columns]}, row, column, column)
  5 个评论

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by