Borrar filtros
Borrar filtros

Delete rows and cols of a sparse matrix

9 visualizaciones (últimos 30 días)
Kris zenitis
Kris zenitis el 10 de Jun. de 2014
Comentada: Matt J el 10 de Jun. de 2014
I ve got a nx3 matrix, which correspont to a nxn sparse matrix with a x,y and the weight z. I want in a for loop to find and delete specific x, y. For example I want iterative to delete from 1 to n the first column and row the second row and column until the nth row and column in order to create n-1 matrices with (n-1 rows and columns). How can I look inside the sparse representatino of the matrix in order to do such a thing?

Respuestas (1)

Matt J
Matt J el 10 de Jun. de 2014
Editada: Matt J el 10 de Jun. de 2014
S=sparse(x,y,z);
C=cell(1,n-1);
tmp=S;
for i=1:n
tmp(1,:)=[];
tmp(:,1)=[];
C{i}=tmp;
end
  1 comentario
Matt J
Matt J el 10 de Jun. de 2014
Or, to have the results in the original three-column form
for i=1:n
tmp(1,:)=[];
tmp(:,1)=[];
[i,j,s]=find(tmp);
C{i}=[i,j,s];
end

Iniciar sesión para comentar.

Categorías

Más información sobre Sparse Matrices en Help Center y File Exchange.

Etiquetas

Productos

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by