Elementwise Multiply Array by Vector without repmat or loop

14 ビュー (過去 30 日間)
JE
JE 2015 年 8 月 7 日
コメント済み: JE 2015 年 8 月 7 日
I would like to do an elementwise multiplication of an array by a column vector. Normally to do this, I would use repmat to get the vector to be the same size as the array and then use .* . However, with very large arrays, I would like to avoid using repmat (because of memory issues). A loop is not an option either because it's too slow. Could you please let me know if there's another way to do this?
e.g., A = [1; 0; 3] and B = [1 4 4 5; 9 4 9 10; 10 9 3 5] so A is 3 x 1 and B is 3 x 4. I want to multiply each column of B by A. I'd normally do the following: repmat(A, 1, 4) .* B However, I was wondering if there was an alternative that didn't use repmat.

採用された回答

Azzi Abdelmalek
Azzi Abdelmalek 2015 年 8 月 7 日
bsxfun(@times,A,B)
  1 件のコメント
JE
JE 2015 年 8 月 7 日
Thanks Azzi. Exactly what I wanted.

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeResizing and Reshaping Matrices についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by