Matrix Multiplication, row by row multiplication and column by column multiplication

35 ビュー (過去 30 日間)
Hi there,
I was wondering what matlab function I can use to multiply a matrix by another matrix and then multiply those two matrices row by row and then column by column. Yielding a total of three matrix multiplications: regular matrix multiplication, row by row multiplication, and column by column multiplication.
Code
%
A = ([ 1 2 3; 4 5 6; 7 8 9]);
B = ([ 2 2 2; 2 2 2 ; 2 2 2]);
%
...For example...
Regular matrix multiplication: A*B = ([12 12 12; 30 30 30; 48 48 48])
%
How can I write it to multiply the matrix row by row and column by column?
Row by row multiplication: RowsA*RowsB = ([12 12 12; 30 30 30; 48 48 48])
Column by column multiplication: ColsA*ColsB = ([12 12 12; 30 30 30; 48 48 48])
Thank you.

採用された回答

madhan ravi
madhan ravi 2018 年 9 月 11 日
編集済み: madhan ravi 2018 年 9 月 11 日
There is no in-built function but you can do this:
A = [ 1 2 3; 4 5 6; 7 8 9]
B = [ 2 2 2; 2 2 2 ; 2 2 2]
A*B %regular matrix multiplication
A.*B %element wise matrix multiplication
[m,n]=size(A)
for i = 1:m
rows(i,:)=A(i,:).*B(i,:) %multiplies rows
end
for i=1:n
columns(:,i)=A(:,i).*B(:,i) % multiplies columns
end
  4 件のコメント
Stephen H
Stephen H 2018 年 9 月 11 日
編集済み: Stephen H 2018 年 9 月 11 日
well, I didn't read the question carefully enough... it just says use 'a' built-in function... so I guess I could just use the regular matrix multiplication. thank you for your help
madhan ravi
madhan ravi 2018 年 9 月 11 日
your welcome:)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCreating and Concatenating Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by