Borrar filtros
Borrar filtros

finding and storing non zero elements in a NxN matrix

4 visualizaciones (últimos 30 días)
Anantha Padmanabhan
Anantha Padmanabhan el 1 de Oct. de 2014
Respondida: Jos (10584) el 2 de Oct. de 2014
Hi, I would like to know how i can determine the non zero elements in a matrix consisting mostly of zeros and store its matrix coordinate positions. So in a 64*64 matrix i can determine the non zero elements by making a for loop like this for ix=1:n
for iy=1:n
if newpositions(ix,iy)==0
%nah u alrite
else
newpsi(ix,iy)=%%%here i want to store the ix and iy elements in an array instead of storing them in a huge ix*iy matrix
end
end
end

Respuestas (2)

José-Luis
José-Luis el 1 de Oct. de 2014

Jos (10584)
Jos (10584) el 2 de Oct. de 2014
help find
M = rand(5) < 0.2 ; % some data
[r,c,v] = find(M) ; % row and column indices of non-zero elements (with values v)

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!

Translated by