简体   繁体   English

如何在matlab中将每一行与另一个矩阵元素的每一行相乘?

[英]how to multiply each row with each row of another matrix elementwise in matlab?

I have such a matrix 我有这样一个矩阵

m1 = [ 1 2 3; 4 5 6; 1 2 3]
m2 = [ 2 2 2];

and I want to multiply each row of m1 with m2 elementwise . 我想将每行m1乘以m2元素。

So result is 结果是

result = [2 4 6; 8 10 12; 2 4 6]

How would I do it? 我该怎么办?

 bsxfun(@times,m1,m2)


ans =

     2     4     6
     8    10    12
     2     4     6

你也可以用

 result = diag(m2)*m1;

暂无
暂无

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

相关问题 将矩阵中的每一列与另一列中的对应行相乘,然后在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 矩阵的每一行乘以另一个矩阵 - Multiply each row of a matrix by another matrix 如何将矩阵A的每一列乘以矩阵B的每一行,并在Matlab中求和矩阵? - How to multiply each column of matrix A by each row of matrix B and sum resulting matrices in Matlab? MATLAB:将矩阵A中的每一列乘以矩阵B中的一行 - MATLAB: Multiply each column in Matrix A by a row in Matrix B Matlab,如何将行矩阵的每个元素与另一个行矩阵的每个元素进行比较? - Matlab, How do I compare each element of a row matrix with each element of another row matrix? 如何将矩阵中的列乘以不同的常数(每列),然后在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 with its transposed self 如何将给定矩阵每一行中的所有元素与给定向量的相应元素相乘,然后在MATLAB中求和? - How do I multiply all the elements in each row of a given matrix with corresponding elements of a given vector and sum them in MATLAB? 将每一行与matlab中的另一行连接起来? - concatenate each Row with another row in matlab?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM