Find out non-zero indexes of rows in matrix

2 vues (au cours des 30 derniers jours)
lucksBi
lucksBi le 10 Juin 2017
Commenté : lucksBi le 10 Juin 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

Réponse acceptée

Walter Roberson
Walter Roberson le 10 Juin 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
  1 commentaire
lucksBi
lucksBi le 10 Juin 2017
Thank You so much :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Matrix Indexing dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by