Calculating the product of array elements in MATLAB

  • Context: MATLAB 
  • Thread starter Thread starter dunyali
  • Start date Start date
  • Tags Tags
    Matlab Product
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
3 replies · 3K views
dunyali
Messages
2
Reaction score
0
Can someone tell me how to do the following in MATLAB (R2010a):

f(1)*f(2)*...*f(n)

thanx in advance.
 
Physics news on Phys.org
I assume that you have already defined the contents of the vector f of length n.
Then
p = prod(f);
 
Hi, marcusl

I have a 4d matrix M, with size: a * b * c * n
This is exactly what I want: M(:,:,:,1).*M(:,:,:,2).*...*M(:,:,:,n) (this is element wise multiplication of the elements)

Please help.
 
Read Matlab's Help entry, which tells you exactly how to take the product over a desired dimension (index). I will help you if you're stuck, but I will not do all your work for you.