Compare values of a matrix
Show older comments
I have a n*n matrix and want to group the numbers together in different classes. I will explain it with a 5*5 matrix. The upper and lower diagonal values are same while the diagonal matrix is always 1. This is a correlation matrix of pairs where (1,2)=(2,1). I have a threshold of 0.9 so whichever value is greater than 0.9 then both the values are clustered in the same group. I will start with row 1. I want to select the values greater than 0.9 which in this case is only 4th. Now I will group (1,4) in group A. I will also in this same iteration find the least value which should be less than 0.9. Here it is 3rd entry which is 0.75. So for the column 3 I move to row 3 in the second iteration. Now I will repeat the same process but I have to only group remaining columns which are not yet grouped which is 2,3,5 by the same rule. In this iteration only 5th is greater than 0.9 so I have (3,5) as the pair and the least value is (3,1) but since I have to only check 2,3,5 (1,4 are already grouped in A) I will look for minimum out of these two (2,5) which is 2. Now I move to row 2. In my algorithm now 2 is the only last remaining factor I'd look for the maximum value in the second row which is (2,5) and will group this remaining 2 with (2,3,5). I will repeat this process till all the items are grouped in groups A, B, C.... and so on. So to group the last remaining row number I just group them with the best value they have row number.
There would not be any case where a factor is common i.e they are in two groups. For example after (1,4) so when we do iteration for 3rd row then 4th column would not have greater value than 0.9 (most likely) because the factors are from certain image features which associates to each other in a way that since 1 is not associated with 3 very well and good with 4 hence 3 would also be not very well associateed with 4.
Please let me know if you have any questions as I think this may confuse you pretty much. Please let me know if you can let me know a simple algorithm which works for this. Thanks in advance.
My final output group will be (1,4),(2,3,5)
0001 0.88 0.75 0.91 0.79
0.88 0001 0.76 0.74 0.97
0.75 0.76 0001 0.76 0.99
0.91 0.74 0.76 0001 0.80
0.79 0.97 0.99 0.80 0001
3 Comments
Rik
on 6 Jul 2019
Is that matrix you show the input or the output? The explanation you give is very difficult to convert to an actual Matlab code. Can you try to describe input and output, and describe the rules in terms of Matlab of how to get from one to the other?
Guillaume
on 6 Jul 2019
I didn't understand the meaning of So for the column 3 I move to row 3 in the second iteration. I think you need to explain what happens on the 2nd step as well.
It would also help if you showed what is the final result for the above matrix.
Abhishek Singh
on 6 Jul 2019
Accepted Answer
More Answers (1)
Bruno Luong
on 6 Jul 2019
0 votes
It seems like you you want to cluster indexes according to correlation. In this case why not threshold you matrix, that gives some sort of connectivity graph, then using some graph technique to get the connex components.
There a a bunch of such function in File Exchange.
Categories
Find more on Creating and Concatenating Matrices 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!