Hello everyone? I have a problem related with sorting and grouping of elements in a matrix, but the problem is a very specific one?
1 回表示 (過去 30 日間)
古いコメントを表示
I will give an example to illustrate my problem. Consider a matrix
A= [1 2;
2 6;
6 1;
3 2];
Now the elements in each row are there because they have some relationship with each other. For example here, in row 1, there is element 1 and element 2, which means that element 1 and element 2 are related with each other, somehow. Similarly row 2 suggests that element 2 is also related with element 6 and row 3 suggests that element 6 is also related with element 1, and finally row 4 suggests that element 2 is also related with element 3. Since from the first three rows we can deduce that elements 1 2 and 6 are related with each other, so that should be grouped together. Element 3 is only related with 2, but not with 1 and 6 and hence can't be grouped with them. So my outcome should be A1=[1 2 6;3 2]; Please note that I have to apply the same logic on a big matrix, with hundreds of rows. The matrices I am working with have sizes (n*2), n=number of rows and 2 columns. Help would be appreciated.
Thank you!
1 件のコメント
Image Analyst
2016 年 5 月 1 日
編集済み: Image Analyst
2016 年 5 月 1 日
Can you not be so secretive and share the bigger picture? For example, like the first column is the age of the male child in the family and the second column is the age of the female child, or whatever. What does "related" mean? in the larger context? I see that you mean it to mean if any number is "connected to" the other number, regardless of what row that connection/pairing happens on, but I'd still like to know the big picture. For example, maybe you could use the gray level cooccurrence matrix, or region growing, or connected components labeling, or something, but I don't really know enough to know if an efficient higher level function like that would work or not. Or another possibility I see is making a graph (node network) out of it and trying to see how many unconnected graphs there are.
採用された回答
Walter Roberson
2016 年 5 月 1 日
s = max(A(:));
B = sparse(A(:,1), A(:,2), 1, s, s);
B = max(B, B.'); %make it symmetric
relates = arrayfun(@(COL) find(B(:,COL)), 1:s, 'Uniform', 0);
8 件のコメント
Image Analyst
2016 年 5 月 2 日
This is why Walter is the awesome master of MATLAB. He seems to know everything. You can also vote for his answer to give him double points for helping you.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Creating and Concatenating Matrices についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!