multiply along

5 visualizaciones (últimos 30 días)
Mate 2u
Mate 2u el 6 de Jun. de 2012
~EDITED'
Hi there, I have a long matrix 1000 x 34 want to do the cumulative multiplication left to right to give a 1000 x 1 matrix then the sum of the multiplication going downwards. So like a sum function but multiplying each element going sideways then downwards.
EDITED THIS ANSWER HAS BEEN ANSWERED but need a follow on answer...

Respuesta aceptada

Oleg Komarov
Oleg Komarov el 6 de Jun. de 2012
sum(cumprod(A))
  2 comentarios
Mate 2u
Mate 2u el 6 de Jun. de 2012
What if their are zeros. Is there a line code to change all zeros to 1s?
Walter Roberson
Walter Roberson el 6 de Jun. de 2012
T = A;
T(T==0) = 1;
sum(cumprod(T))

Iniciar sesión para comentar.

Más respuestas (1)

Walter Roberson
Walter Roberson el 6 de Jun. de 2012
If the numbers are strictly positive, you could log() and cumsum() and exp() the result.

Categorías

Más información sobre Logical en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by