简体   繁体   English

MATLAB:将矩阵A中的每一列乘以矩阵B中的一行

[英]MATLAB: Multiply each column in Matrix A by a row in Matrix B

Matrix A: 10 rows, 50 columns 矩阵A:10行50列

a1 a2 a3 .... a1 a2 a3 ....

b1 b2 b3 .... b1 b2 b3 ....

c1 c2 c3 .... ... c1 c2 c3 .... ...

Matrix B: 50 rows, 10 columns 矩阵B:50行10列

x1 x2 x3.... x1 x2 x3 ....

y1 y2 y3.... y1 y2 y3 ....

.... ....

I would like to multiply data in each rows in Matrix A by columns(1) in Matrix B, the results will look like: 我想将矩阵A中每一行的数据乘以矩阵B中的column(1),结果将如下所示:

[ x1 *a1, x2 *b1, x3 *c1, x4 *d1.... [ x1 * a1, x2 * b1, x3 * c1, x4 * d1 ....

x1 *a2, x2 *b2, x3 *c2, x4 *d2.... x1 * a2, x2 * b2, x3 * c2, x4 * d2 ....

x1*. x1 *。

....] ....]

Then, multiply each rows of Matrix A by columns(2) in Matrix 8: 然后,将矩阵A的每一行乘以矩阵8中的column(2):

[ y1 *a1, y2 *b1, y3 *c1, y4 *d1.... [ y1 * a1, y2 * b1, y3 * c1, y4 * d1 ....

y1 *a2, y2 *b2, y3 *c2, y4 *d2.... y1 * a2, y2 * b2, y3 * c2, y4 * d2 ....

y1* . y1 * ....] ....]

Then, by row(3) till columns(50) 然后,按第(3)行直到第(50)列

I am looking for a script : ) 我正在寻找一个脚本:)

You can use bsxfun . 您可以使用bsxfun

A=rand(10,50);
B=rand(50,10);
C=bsxfun(@times,A,permute(B,[3 1 2]));

Here C(:,:,1) would be your first result matrix, and C(:,:,2) the second... 这里C(:,:,1)是您的第一个结果矩阵,而C(:,:,2)是第二个结果矩阵。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何将矩阵A的每一列乘以矩阵B的每一行,并在Matlab中求和矩阵? - How to multiply each column of matrix A by each row of matrix B and sum resulting matrices in Matlab? 将矩阵中的每一列与另一列中的对应行相乘,然后在Matlab中求和 - Multiply each column in a matrix by corresponding row in another and sum results in Matlab Matlab将矩阵中的每一行乘以不同的数字 - Matlab multiply each row in matrix by different number 如何在matlab中将每一行与另一个矩阵元素的每一行相乘? - how to multiply each row with each row of another matrix elementwise in matlab? 如何将矩阵中的列乘以不同的常数(每列),然后在Matlab中将每一行求和? - How to multiply a columns in a matrix by a different constant (per column) and then summing each row up in Matlab? 矩阵的每一行乘以另一个矩阵 - Multiply each row of a matrix by another matrix 将矩阵A的每行中的每个值乘以矩阵B中特定行的每个对应值 - Multiply each value in rows of Matrix A by each corresponding value of a specfic row in Matrix B 将矩阵的每列乘以另一个矩阵 - Multiply each column of a matrix by another matrix MATLAB:将每列1x3xN矩阵乘以相应的3x3xN旋转矩阵 - MATLAB: multiply each column 1x3xN matrix by corresponding 3x3xN rotation matrix 在MATLAB中将每个子块与矩阵相乘 - Multiply each sub-block with a matrix in MATLAB
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM