Iteratively remove the rows and columns of a matrix
3 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have a matrix H, which obtains the strcuture as shown below. H is block sparse, where each color block denotes non-empty block and white color denote block with all zeros. Each row and column of H has N blocks. Each block is of size M \times M.

Now I have another matrix C, which is obtained via first vectorize H denoted by h=vec(H), then C=h*h^H, where ^H denotes Hermitian operation. So actually C is a sample covariance matrix. My goal is to densify the matrix C. Densify means I want to remove all zeros rows and columns of C based on the structure H or equivalently h.
My current question is I have loop to find the index where h are non zero. For example, for the first part of h, which in the range 1:NM of h, 1: 2M are non-zero and 2M:(N-2)M is empty,. Then I remove all the rows of C from 2M:(N-2)M, and do the same for columns of C as well. However, after removing the zeros rows and columns in C in this iteration, it becomes difficult for me to find the proper index as the size of C has changed in last iteration.
Therefore, is there any convenient way to implmenet the matrix C densify?
Note that densify h or H then compute C can not be done due to the other parts limits of my project.
0 comentarios
Respuestas (2)
Chuguang Pan
el 13 de Abr. de 2025
Editada: Chuguang Pan
el 13 de Abr. de 2025
M = 3;
N = 8;
[H00,H10,H20,H30,H40,H50,H60,H70] = deal(randi(10,M));
[H11,H21,H31,H41,H51,H61,H71] = deal(randi(20,M));
H = blkdiag(H00,H10,H20,H30,H40,H50,H60,H70) + [zeros(1*M,N*M);blkdiag(H11,H21,H31,H41,H51,H61,H71) zeros((N-1)*M,1*M)];
h = H(:);
C = h*h';
nnzIdx = find(h);
nnzH = C(nnzIdx,nnzIdx)
1 comentario
Chuguang Pan
el 13 de Abr. de 2025
Editada: Chuguang Pan
el 13 de Abr. de 2025
@charrrrlie I use find function to extrat nonzero element index from sparse vector h and extract the nonzero elements from C matrix using nonzero element index.
Ver también
Categorías
Más información sobre Sparse Matrices en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!