MATLAB Answers

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

2 views (last 30 days)
fyza affandi
fyza affandi on 28 Nov 2018
Commented: Guillaume on 29 Nov 2018
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

  0 Comments

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 28 Nov 2018
[row, column] = find(Matr);
groups = splitapply(@(rows, columns) {[rows, columns]}, row, column, column)

  5 Comments

Show 2 older comments
Guillaume
Guillaume on 29 Nov 2018
celldisp(groups)
To see the content of the cell array, which is exactly what you asked for.

Sign in to comment.

More Answers (0)


Translated by