grouping non-zero entries in a matrix according to a rule
2 views (last 30 days)
Show older comments
I have a matrix say, a = [ 0 1 0 0 0 1 0; 0 0 0 0 0 1 1; 1 0 0 0 0 0 0; 0 1 0 0 0 0 0; 0 0 1 0 1 0 0; 0 0 0 1 0 0 1;]
I need to enumerate the non-zero elements into groups according to the following: - if two elements share a row or a column they are in the same group, and if say (1,2) & (1,6) in group1, then group1 will also include (2,6) & (2,7) & (6,7) & (4,2) & (6,4) I have been stuck with this for a while, any help is deeply appreciated.
0 Comments
Accepted Answer
Matt J
on 14 Apr 2014
Edited: Matt J
on 14 Apr 2014
How about this
[I,J]=find(a);
C=bsxfun(@eq,I,I.') | bsxfun(@eq,J,J.');
The matrix C is a graph connectivity map which you can then use to segment into groups using this FEX file,
More Answers (0)
See Also
Categories
Find more on Directed Graphs in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!