フィルターのクリア

How to multiply all elements of matrix

3 ビュー (過去 30 日間)
Ram k
Ram k 2016 年 5 月 6 日
回答済み: Stephen23 2016 年 5 月 6 日
Suppose I have a matrix
0 0.3333 0 0 0.6667
0 0 1.0000 0 0
0 0 0 0 1.0000
1.0000 0 0 0 0
0.4000 0 0 0.2000 0.4000
I want to multiply nonzero elements of above matrix i.e. 0.3333*0.6667*1*1*1*0.4*0.2*0.4=0.00711. How to do this.

回答 (2 件)

Azzi Abdelmalek
Azzi Abdelmalek 2016 年 5 月 6 日
prod(nonzeros(A(:)))
  1 件のコメント
Guillaume
Guillaume 2016 年 5 月 6 日
You don't even need the (:) since nonzeros will return a vector anyway:
prod(nonzeros(A))

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


Stephen23
Stephen23 2016 年 5 月 6 日
prod(A(A~=0))

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by