Extract part of a sparse matrix
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
Pedro Montenegro
el 2 de Mayo de 2014
Comentada: Azzi Abdelmalek
el 2 de Mayo de 2014
Dear users,
I'm trying to find a way to extract a block from a big sparse matrix without being computationally costly. Here what I have
A - sparse matrix n*n i - a vector with the indices I want to extract (i = [5556 68424 85345 925325], for example)
I can do what I want like this:
A_new = A(i,i).
However, this indexing that is used in full matrices is not effective for sparse. how can I do this operation in an effective way?
Thank you in advance,
Pedro Montenegro University of Porto, Portugal
0 comentarios
Respuesta aceptada
Azzi Abdelmalek
el 2 de Mayo de 2014
i = [5556 68424 85345 925325];
ii=sub2ind(size(A),i,i)
A_new = A(ii)
2 comentarios
Azzi Abdelmalek
el 2 de Mayo de 2014
[ii,jj]=ndgrid(i,i)
idx=sub2ind(size(a),ii(:),jj(:))
a(idx)
Más respuestas (0)
Ver también
Categorías
Más información sobre Creating and Concatenating 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!