Taking each column and element wise multiply to a matrix

4 visualizzazioni (ultimi 30 giorni)
I'm wondering if there is a faster way to do this operation. Here is an example scenario:
A = randn(3, 26);
B = randn(3, 128);
Now I want to take each column of A and do element-wise multiplication with B. I know that I can use a for loop for example:
for i = 1:26
bsxfun(@times, a(:, 1), x)
end
My question: is there any way to do this without a for loop? Thanks.
  2 Commenti
Ernst Schwartz
Ernst Schwartz il 23 Nov 2018
hi! did you find a solution? I'm having the same problem.
Stephen23
Stephen23 il 23 Nov 2018
Modificato: Stephen23 il 23 Nov 2018
Perhaps kron does what you want.

Accedi per commentare.

Risposte (1)

Andrei Bobrov
Andrei Bobrov il 23 Nov 2018
out = bsxfun(@times,reshape(A,size(A,1),1,[]),B);

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by