sortmatrix function

Organise matrix by topology