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!

 채택된 답변

Jonathan
Jonathan 2011년 11월 11일

0 개 추천

See if this works for you.
A = primes(100);
B = A(1:end-1) .* A(2:end);

댓글 수: 2

lachelle
lachelle 2011년 11월 11일
thank you so much!
Hector Koch
Hector Koch 2016년 3월 31일
Could you give insight on how this exactly works? Is it possible to use a loop here as well?

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

태그

질문:

2011년 11월 11일

댓글:

2016년 3월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by