Clear Filters
Clear Filters

How to multiply matrix with matrix, only between their component counterparts

3 views (last 30 days)
Hi,
if I have matrices A and B
A=[ 1 2 ; 3 4]
B=[10 20; 30 40]
are there a fast/straightforward operation in which the result is matrix C
C=[1x10 2x20 ; 3x30 4x40] ?
Obviously, calculation with 4 loops is what I would like to avoid.
Thank you in advance.

Accepted Answer

Arif Hoq
Arif Hoq on 19 Feb 2022
Edited: Arif Hoq on 19 Feb 2022
you need to multiplication element by element. you should use a dot (.) before any multiplication (*), division (/), or power (^) operators that involve vectors.
A=[ 1 2 ; 3 4];
B=[10 20; 30 40];
C=A.*B
C = 2×2
10 40 90 160

More Answers (0)

Categories

Find more on Matrices and Arrays in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!