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

AI Thread Summary
The discussion revolves around the computation of a specific matrix operation involving two 3D matrices, A and B, with dimensions 60x60x100 and 60x60x30, respectively. The goal is to calculate a resulting 100x30 matrix where each element (k,m) is the sum of the products of corresponding elements from the k-th slice of A and the m-th slice of B, summed over all indices i and j. A user seeks a concise code snippet to achieve this operation. A proposed solution in a loop format suggests iterating through the dimensions of the output matrix and using element-wise multiplication followed by summation to compute the desired results. The discussion highlights the need for clarity in matrix operations and coding assistance for users unfamiliar with the programming environment.
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
 

Similar threads

Replies
1
Views
2K
Replies
6
Views
2K
Replies
2
Views
1K
Replies
10
Views
3K
Replies
8
Views
2K
Replies
3
Views
4K
Replies
1
Views
3K
Back
Top