Effortlessly Compute A*B with MATLAB: Simple 100x30 Output Matrix Calculation

  • Context: MATLAB 
  • Thread starter Thread starter mikeph
  • Start date Start date
  • Tags Tags
    Computation Matlab
Join the discussion
Ask a follow-up here, or get your own question answered by working scientists, mathematicians and engineers — people, not an autocomplete.
Real named experts · corrections over time · the nuance an AI answer skips
1 reply · 2K views
mikeph
Messages
1,229
Reaction score
18
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?
 
Physics news on Phys.org
MikeyW said:
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?

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)))

NR