multiplying adjacent values in matrix

16 visualizzazioni (ultimi 30 giorni)
lachelle
lachelle il 11 Nov 2011
Commentato: Hector Koch il 31 Mar 2016
How do you multiply adjacent values within a single matrix in matlab? My matrix is compiled with the prime numbers before 100. ie. primes(100), if the first values are 2 3 5 7 and i need to multiply 2*3 3*5 5*7 and so on.. thanks!

Risposta accettata

Jonathan
Jonathan il 11 Nov 2011
See if this works for you.
A = primes(100);
B = A(1:end-1) .* A(2:end);
  2 Commenti
lachelle
lachelle il 11 Nov 2011
thank you so much!
Hector Koch
Hector Koch il 31 Mar 2016
Could you give insight on how this exactly works? Is it possible to use a loop here as well?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Resizing and Reshaping Matrices in Help Center e File Exchange

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by