I have a matrix:
1 2 3 4 5 6
1 0.7431 0.2769 0.0000 0.1869 0.2760 0.9597
2 0.2769 0.0462 0.0344 0.4898 0.6797 0.3404
3 0.0000 0.0344 0.4387 0.4456 0.6551 0.0000
4 0.1869 0.4898 0.4456 0.6463 0.1626 0.2238
5 0.2760 0.6797 0.6551 0.1626 0.1190 0.7513
6 0.9597 0.3404 0.0000 0.2238 0.7513 0.2551
Integers are index. I have a hash table in which each index is a person. Decimals are interactions between indices. Now I want to subset this matrix with a index list (1, 3, 6), which means I only care the interaction among 1, 3 and 6.
Subset:
1 3 6
1 0.7431 0.0000 0.9579
3 0.0000 0.4387 0.0000
6 0.9579 0.0000 0.2551
There are no interactions between some people, e.g. person 1 and 3 or person 3 and 6. But 1 is interacts with 2, 4, 5 and 6 which interact with 3. So 1 interacts 3 through 2, 4, 5 or 6. It can be 1->2->4->3 or 1->4->3 something like that. I want to find the shortest path for those 2 nodes that have no direct interactions. I want to subset the original matrix and then find the shortest path between the nodes that don't have interactions. Sorry guys, I didn't make myself clear.
I think you want to look at Dijkstra's algorithm:
There is a Mathworks file exchange algorithm that calculates Dijkstra's algorithm here:
http://www.mathworks.com/matlabcentral/fileexchange/36140-dijkstra-algorithm
I have used it to calculate shortest paths before...it's pretty efficient and guaranteed optimal. There's really no need to subset the matrix...if there are nodes you don't want to consider, just don't put them in your matrix.