Find out indexes of zeroed elements in matrix

1 回表示 (過去 30 日間)
lucksBi
lucksBi 2017 年 6 月 12 日
編集済み: David Goodmanson 2017 年 6 月 12 日
hey
how can i find out indexes of zeroed 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 2;3;5;6 for row 1, 5 for row2 and 2;6 for row3.
Thanks

採用された回答

David Goodmanson
David Goodmanson 2017 年 6 月 12 日
編集済み: David Goodmanson 2017 年 6 月 12 日
Hi lucksBi, the find command gives you the row and column indices for a given condition. The find command searches column by column but you are more interested in row by row, so in this case it's better to use the transpose of the matrix
[a b] = find(matrix.'==0];
inds = [b a]
inds =
1 2
1 3
1 5
1 6
2 5
3 2
3 6
  1 件のコメント
lucksBi
lucksBi 2017 年 6 月 12 日
hey Thanks alot for helping.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMatrix Indexing についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by