필터 지우기
필터 지우기

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일

카테고리

Help CenterFile Exchange에서 Multidimensional Arrays에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by