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
Click For Summary
SUMMARY

The discussion focuses on computing the product of two 3D matrices, A and B, using MATLAB to generate a 100x30 output matrix. The matrices A and B have dimensions of 60x60x100 and 60x60x30, respectively. The desired output matrix element (k,m) represents the sum of the products of corresponding elements from the k-th slice of A and the m-th slice of B. A MATLAB code snippet is provided, utilizing nested loops and the sum function to achieve this computation.

PREREQUISITES
  • Understanding of MATLAB syntax and operations
  • Familiarity with 3D matrix manipulation in MATLAB
  • Knowledge of element-wise multiplication and summation
  • Basic programming concepts such as loops and indexing
NEXT STEPS
  • Explore MATLAB's built-in functions for matrix operations
  • Learn about MATLAB's array manipulation techniques
  • Investigate optimization methods for large matrix computations in MATLAB
  • Study advanced indexing techniques in MATLAB for efficient data access
USEFUL FOR

Mathematics students, data scientists, and engineers who need to perform complex matrix calculations in MATLAB, particularly those working with 3D data structures.

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 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
8K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 10 ·
Replies
10
Views
4K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 8 ·
Replies
8
Views
2K
  • · Replies 3 ·
Replies
3
Views
4K