MATLAB: Sparse matrix re-ordering

sparse

Hello everyone,
I have a question I'd like to ask.
When you have a (sparse) matrix, you can plot the graph and find the degree of nodes. When some re-ordering is applied, the sequence of the nodes changes form the lowest degree to the highest degree.
Example: suppose I have a 10 node system with the following degrees: 3-3-5-3-5-2-6-3-1-3. (Node:1-2-3-4-5-6-7-8-9-10)
Now I apply a re-ordering based on the degrees, and my node sequence now becomes: 9-6-1-2-4-8-10-3-5-7.
How do I find the updated matrix from this new sequence? Is there a specific MATLAB function, or do I need to write some code?
Any help is really appreciated.
Romeo

Best Answer

I tried to generalize your code as follows.
A = [-1 -2 0 4 0 0 0 1 0 0;
3 2 0 0 0 0 -4 0 0 3;
0 0 5 7 -6 0 3 4 0 1;
2 0 1 1 -1 0 0 0 0 0;
0 0 2 4 -1 8 6 0 0 3;
0 0 0 0 2 -2 4 0 0 0;
0 3 -3 0 1 9 5 -3 -6 0;
-1 0 2 0 0 0 4 -5 0 0;
0 0 0 0 0 0 -1 0 2 0;
0 2 2 0 5 0 0 0 0 7];
% Store the graph info for the original array, in the first element of a
% new cell array
G{1} = graph(A,'upper');
N = length(A);
% Initialize the output as an empty vector that we will append to
output = nan(N,1);
original = 1:N;
for i = 1:N
% Find the degree list (and store for later inspection)
deg{i} = degree(simplify(G{i}));
% Sort the degree list
[deg{i},k] = sort(deg{i},'ascend');
% Remove lowest degree from graph, and store new graph
G{i+1} = rmnode(G{i},k(1));
% Add lowest degree position to output
output(i) = original(k(1));
% Delete the lowest degree position from the original list
original(k(1)) = [];
end
However, I don't get the same final output as you state. (The first few match with yours.)
I can't determine whose is incorrect. I tried to comment my code very carefully, so that you could follow what I did, and find a coding mistake.