简体   繁体   中英

R or MATLAB: permute a large sparse matrix into a block diagonal matrix

I have a large sparse matrix, and I want to permute its rows or columns to turn the original matrix into a block diagonal matrix. Anyone knows which functions in R or MATLAB can do this? Thanks a lot.

I'm not really set up to test this, but for a matrix m I would try:

p = symrcm(m);
block_m = m(p,p);

If that doesn't work, look through the other functions listed in help sparfun to see if any will help you out.

seriation包R具有在与此相关的一个问题的一些工具。

Not exactly sure if this is what you want, but in MATLAB this is what I have used in the past. Probably not the most elegant solution. I go from sparse to full and then chop the thing into square blocks.

A=full(A);

Then:

blockedmatrix = mat2cell(A, (n*ones(1,size(A,1)/n)), ...
(n*ones(1,size(A,1)/n))); %found somewhere on internetz

This returns a cell, where each entry is of size nxn. It's easy to extract the blocks of interest, manipulate them, and then restore them to a matrix with cell2mat.

Maybe a bit late to the game, but since there are available commands, here is a simple one. If you have a matrix H and the block diagonal form is needed, you can obtain it through the following lines ( MATLAB ):

[p,q] = dmperm(H);
H(p,q)

which is equivalent to Dulmage - Mendelsohn permutation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM