I have a correlation matrix X of five elements(C1,C2,C3,C4,C5)
C1 C2 C3 C4 C5
C1 * 1 0 1 0
C2 1 * 0
What you're looking for is probably the reverse Cuthill-McKee algorithm (RCM), which pretty much does what you want: for a given matrix it finds a permutation that tends to have its non-zero elements closer to the diagonal. There's a built-in function symrcm in MATLAB that does just that.
So assuming that X
is your matrix, you can do the following:
p = symrcm(X);
Xnew = X(p, p);
Xnew
is the new reordered matrix, and p
is the new row/column order.
Let's create a matrix first:
X = [10 0 0 7 0; 3 20 0 0 11; 0 0 30 0 29; 12 7 0 40 0; 0 33 0 0 50]
Now let's reorder it:
p = symrcm(X);
Xnew = X(p, p)
The result is:
Xnew =
40 12 7 0 0
7 10 0 0 0
0 3 20 11 0
0 0 33 50 0
0 0 0 29 30
Seems right.