How to multiply all elements of matrix
조회 수: 6 (최근 30일)
이전 댓글 표시
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.
댓글 수: 0
답변 (2개)
Azzi Abdelmalek
2016년 5월 6일
prod(nonzeros(A(:)))
댓글 수: 1
Guillaume
2016년 5월 6일
You don't even need the (:) since nonzeros will return a vector anyway:
prod(nonzeros(A))
참고 항목
카테고리
Help Center 및 File Exchange에서 Resizing and Reshaping Matrices에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!