How do I count the number of zeros in a matrix?

4 ビュー (過去 30 日間)
luis suarez
luis suarez 2019 年 12 月 23 日
回答済み: Walter Roberson 2019 年 12 月 23 日
I want to display the rows which has the maximum number of zero elements and if the matrix has two rows which have the same number of zeros I want to display both. Can someone help me please. Thank you
NB: Consoder the two matrices below
A=[0 0 1;2 3 4;7 8 9]
The results should be row 1
B=[0 1 2;3 0 5;7 8 9]
The result for matrix B should be rows 1 and 2.

回答 (1 件)

Walter Roberson
Walter Roberson 2019 年 12 月 23 日
Hint: A == 0 has the value 1 where entries are 0, and the value 0 where the entries were not zero. What happens if you total these values along the rows?

カテゴリ

Help Center および File ExchangeShifting and Sorting Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by