How to multiply row of matrix A with column of matrix B?
6 次查看(过去 30 天)
显示 更早的评论
A is 121 x 36 matrix
B is 36 x 121 matrix
The result C should be 121 x 1 matrix.
May I know how should I multiply a row of A with col of B? so that resulting matrix is 121 X 1.
No loops please.
2 个评论
the cyclist
2021-11-24
One row of A is 36 elements. One column of B is 36 elements. It is absolutely unclear how to get a 121x1 matrix from that.
Please explain more clearly what you need. Perhaps use a smaller example (e.g. 4x3) to show exactly what the input and output should be.
采纳的回答
James Tursa
2021-11-25
编辑:James Tursa
2021-11-25
Maybe this is what you want?
C = sum(A .* B.',2)
0 个评论
更多回答(1 个)
the cyclist
2021-11-24
If @Adam Danz is correct that you actually want to multiply all the elements of one column of A with one row of B, then
% Define A and B
A = rand(121,36);
B = rand(36,121);
% Which row and column?
colA = 2;
rowB = 3;
% Multiply the selected row and column
V = A(:,colA) .* B(rowB,:).'; % <----- Note that I used the transpose here
% Check the size of V
size(V)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!