Find out non-zero indexes of rows in matrix

2 visualizaciones (últimos 30 días)
lucksBi
lucksBi el 10 de Jun. de 2017
Comentada: lucksBi el 10 de Jun. de 2017
hey
how can i find out indexes of non-zero elements of all rows in a matrix.e.g.
matrix= [1,0,0,2,0,0;1,2,6,5,0,3;1,0,2,9,4,0]
it'll show 1;3 for row 1, 1;2;3;4;6 for row2 and 1;3;4;5 for row3.
And also instead of doing for whole matrix if i ask for a specific row e.g. row 1 then it'll show 1;3 only.
Thanks

Respuesta aceptada

Walter Roberson
Walter Roberson el 10 de Jun. de 2017
[c, r] = find(matrix.');
indices = accumarray(r, c, [size(matrix,1), 1], @(L) {L.'} );
now indices{K} will be the list of non-zero columns in row #K

Más respuestas (0)

Categorías

Más información sobre Matrix Indexing en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by