Hello!
I have vector matrix A (3x1) and row matrix B (1x3). When multipying A*B, instead of having each element in the new 3x3 matrix be the elements multiplied together, is there a way to still make the 3x3 matrix but instead of each element of one matrix being multiplied by the elements of the other matrix, they would be added together.
If I don't make sence please tell me, I am new to MATLAB. Image of desired outcome below.
Thanks!
Kevin

 採用された回答

Star Strider
Star Strider 2020 年 10 月 10 日

0 投票

Yes, there is!
Try this:
A = [2; 3; 4];
B = [1 3 5];
C = bsxfun(@times, A, B) % Before R2016b
C = A * B % R2016b And Later
producing (for both):
C =
2 6 10
3 9 15
4 12 20
.

4 件のコメント

Kevin Shen
Kevin Shen 2020 年 10 月 10 日
Sorry for the trouble, but I posted the wrong picture originally, there is a new one.
Star Strider
Star Strider 2020 年 10 月 10 日
No worries!
The code for ‘C’ changes slightly:
C = bsxfun(@plus, A, B) % Before R2016b
C = A + B % R2016b And Later
producing:
C =
3 5 7
4 6 8
5 7 9
.
Kevin Shen
Kevin Shen 2020 年 10 月 10 日
Thank you so much!
Star Strider
Star Strider 2020 年 10 月 10 日
As always, my pleasure!

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

その他の回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange で Creating and Concatenating Matrices についてさらに検索

質問済み:

2020 年 10 月 10 日

コメント済み:

2020 年 10 月 10 日

Community Treasure Hunt

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

Start Hunting!

Translated by