How to perform an array multiplication for a vector and a matrix and output results as a matrix?
3 ビュー (過去 30 日間)
古いコメントを表示
Here is the problems and solution which seems very bad. Could anyone suggest a better solution?
M = [1 2 3];
C = [10 11 12; 13 14 15; 16 17 18; 19 20 21; 22 23 24];
K1=C(1,:).*M
K2=C(2,:).*M
K3=C(3,:).*M
K4=C(4,:).*M
K5=C(5,:).*M
B = vertcat(K1,K2,K3,K4,K5)
0 件のコメント
採用された回答
the cyclist
2013 年 7 月 5 日
編集済み: the cyclist
2013 年 7 月 5 日
You might want this instead:
B = bsxfun(@times,C,M)
その他の回答 (2 件)
the cyclist
2013 年 7 月 5 日
編集済み: the cyclist
2013 年 7 月 5 日
Matrix multiplication is a core MATLAB function. I think you just want
B = C * M'
Notice that that is just a "*", not a ".*" (which is element-by-element) multiplication, and that I had to transpose M.
3 件のコメント
the cyclist
2013 年 7 月 5 日
編集済み: the cyclist
2013 年 7 月 5 日
I forgot the transpose when I first posted. Also, I just looked at your B matrix, and it seems you do not want simply matrix multiplication after all.
You expect the result to be a 5x3 and not a 5x1, right?
参考
カテゴリ
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!