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

조회 수: 2 (최근 30일)
fyza affandi
fyza affandi 2018년 11월 28일
댓글: Guillaume 2018년 11월 29일
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
fyza affandi
fyza affandi 2018년 11월 29일
I get this answer
groups =
[3x2 double]
[3x2 double]
Guillaume
Guillaume 2018년 11월 29일
celldisp(groups)
To see the content of the cell array, which is exactly what you asked for.

댓글을 달려면 로그인하십시오.

추가 답변 (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