Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Simple MATLAB computation

  1. May 14, 2012 #1
    hi simple computation

    A = 60x60x100
    B = 60x60x30

    I want to find A*B, by this I mean, I want a 100x30 output matrix where element (k,m) represents the sum of A(i,j,k)*B(i,j,m) over all i,j

    My brain is simply not working and I'm confusing myself, does anyone have a short line of code to calculate this sum?
  2. jcsd
  3. Jun 1, 2012 #2
    If I understand you correctly, then you want to perform an element-by-element multiplication of the k-th plane of A and the m-th plane of B and sum the products to form 100 x 30 matrix?

    I'm not a Matlab user, but would something like the following be along the right kind of lines?

    for k = 1:100
    for m = 1:30
    p(k,m)=sum(sum(A(:,:,k) .* B(:,:,m)))

Share this great discussion with others via Reddit, Google+, Twitter, or Facebook