Using a for loop, how can I multiply diagonal elements of a matrix NxN?

4 visualizaciones (últimos 30 días)
I have an exapmle below which gets the product of the fisrt row an N columns. I am new to mathlab.
Using a for loop like below, how can I multiply diagonal elements of a matrix NxN? thank you
NxN
rowelements= 1 ;
product = 1.0 ;
for(column = 1:N)
product = product*B(row1elements,column) ;
end
  1 comentario
Star Strider
Star Strider el 13 de Dic. de 2019
You likely do not need the loop.
You can get the diagonal elements of the square matrix with the diag function.

Iniciar sesión para comentar.

Respuesta aceptada

Matt J
Matt J el 13 de Dic. de 2019
product = product*B(column,column) ;

Más respuestas (0)

Categorías

Más información sobre Operating on Diagonal Matrices en Help Center y File Exchange.

Productos


Versión

R2019b

Community Treasure Hunt

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

Start Hunting!

Translated by