How to obtain the original matrix after performing symrcm or symamd in MATLAB?
7 views (last 30 days)
Show older comments
Kadyr Sherfedinov
on 8 Oct 2019
Commented: Fabio Freschi
on 9 Oct 2019
I use the Cuthill-McKee algorithm. After finding the desired vector, I need to restore the original matrix. I found the answer here https://www.mathworks.com/matlabcentral/answers/94946-how-do-i-obtain-the-original-mapping-after-performing-symrcm-in-matlab-7-1-r14sp3 but for my images I get "Index exceeds matrix dimensions". Is there any other way to do this? (Preferably without the availability of the original matrix)
symV %original matrix
k1 = symrcm(symV)
matrix_after_cm = symV(k1,k1);
spy(first_after_cm)
0 Comments
Accepted Answer
Fabio Freschi
on 9 Oct 2019
Can you share the symV original matrix?
2 Comments
Fabio Freschi
on 9 Oct 2019
I run your code, then I run
[~,q] = sort(k1);
AfromB = first_after_cm(q,q); % Elapsed time is 0.002503 seconds.
norm(AfromB-symV) % ans = 0
without any problem. Note that your matrix is really sparse, so you can benefit handling it as sparse matrix. Can you try this
symV = sparse(symV);
before symrcm? It is not as smart as directly assembling the matrix as sparse, but it should work.
More Answers (1)
Fabio Freschi
on 8 Oct 2019
Try this:
% matrix dimensions
N = 5;
% create symmetric matrix
A = rand(N);
A = A+A.';
% symrcm sorting
p = symrcm(A);
% sorted matrix
B = A(p,p);
% inverse sorting
[~,q] = sort(p)
% re-create A matrix
AfromB = B(q,q);
% chech
norm(A-AfromB);
% ans =
%
% 0
1 Comment
See Also
Categories
Find more on Sparse Matrices in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!