Filter löschen
Filter löschen

How to multiply all elements of matrix

3 Ansichten (letzte 30 Tage)
Ram k
Ram k am 6 Mai 2016
Beantwortet: Stephen23 am 6 Mai 2016
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.

Antworten (2)

Azzi Abdelmalek
Azzi Abdelmalek am 6 Mai 2016
prod(nonzeros(A(:)))
  1 Kommentar
Guillaume
Guillaume am 6 Mai 2016
You don't even need the (:) since nonzeros will return a vector anyway:
prod(nonzeros(A))

Melden Sie sich an, um zu kommentieren.


Stephen23
Stephen23 am 6 Mai 2016
prod(A(A~=0))

Kategorien

Mehr zu Multidimensional Arrays finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by