フィルターのクリア

how to count the number of non zero elements present in each row and column.

6 ビュー (過去 30 日間)
jaah navi
jaah navi 2019 年 6 月 6 日
コメント済み: Image Analyst 2019 年 6 月 6 日
If a=[3.6910 4.5873 0 0 0;
0 7.2707 0 0 3.7516;
0 0 0 0 0]
I want to count the number of non zero elements present in every row and column
I tried with the following command numel(a) where it gives the entire number of elements present in a.
Could anyone please help me on this.
  2 件のコメント
jaah navi
jaah navi 2019 年 6 月 6 日
I got the result with the following command
sum(C1,2)
sum(C1~=0)
sorry for the trouble.
Image Analyst
Image Analyst 2019 年 6 月 6 日
No, that is not right.

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

採用された回答

Image Analyst
Image Analyst 2019 年 6 月 6 日
Try this
zerosInColumn = sum(a ~= 0, 1);
zerosInRow = sum(a ~= 0, 2);
  2 件のコメント
jaah navi
jaah navi 2019 年 6 月 6 日
yes correct.
Could you please help me with the following issue with respect to the matrix
a= [ 0 3.4977 0 3.5558 4.3476;
3.6415 3.9859 4.2807 4.3479 2.9773;
3.7784 0 3.7328 0 0]
I want to execute the above two comments such that the zerosInColumn and zerosInRow should not be equal to zero and it should be equal to 1,which means i want to get the output in the following manner.Could you please help me on this. zeros In rows =1
1
1
and zeros in column= 1 1 1 1 1
Image Analyst
Image Analyst 2019 年 6 月 6 日
I answered a very very similar question that you asked here in this link

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

その他の回答 (0 件)

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by