一个关于数组特征值统计的问题。

现有一个数组
A=[1 2 3 6 5 8 9 0 0
     1 4 7 8 5 2 3 6 9
     1 4 7 8 9 0 0 0 0
     1 2 3 6 9 0 0 0 0
     1 4 5 6 9 0 0 0 0 ]
现想通过一个函数 B=long_1(A) 得到B=[7 9 5 5 5]'
请问各位大神该怎么编写这个函数?
即求每行的非零数值的个数

 採用された回答

wiwiyoy
wiwiyoy 2022 年 11 月 16 日

0 投票

function B=long_1(A)
     B=sum(A~=0,2)
end

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange稀疏矩阵 についてさらに検索

タグ

質問済み:

2022 年 11 月 16 日

回答済み:

2022 年 11 月 16 日

Community Treasure Hunt

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

Start Hunting!