I have a 200 x 200 adjacency matrix called M. This is the connection strength for 200 nodes (the nodes are numbered 1 to 200 and organized in ascending order in M - i.e., M(23,45) is the connection strength of node 23 and 45). Out of these 200 nodes, I'm interested in three subsets of nodes.
subset1 = [2,34,36,42,69,102,187];
subset2 = [5,11,28,89,107,199];
subset3 = [7,55,60,188];
Using M, I would like to conduct the following operations:
Average of the connection strength within subset1, subset2, and subset3, separately. For instance, for subset1, that would be the mean connection of all possible pairs of nodes 2, 34, 26,..., 187.
Find the connection strength between subset1, subset2, and subset3. This would be the average of connection strength between all pairs of node spanning all possible pairs of the three subsets (average of connection between subset1 & subset2, subset2 & subset3, and subset1 & subset3). Do note that this between connection does not equate putting all the nodes from three subsets into a single matrix (e.g., connection between two subsets is the mean connection of each node in one subset with every node in the other subset).
What I've tried so far was indexing M using a for loop. It was bulky, especially when I have a large number of nodes in each subset. Can someone help?
M1 = M(subset1, subset1);
ind = triu(true(size(M1)), 1); % upper triangle
M1_avg = mean(M1(ind));
I will leave M2_avg and M1_M2_avg to you.