say, A = [A1 A2 .... Am] where A1, A2, ... Am are column vectors.
I want the result B = [w(1)*A1 w(2)*A2 .... w(m)*Am]
I can get this by B = A*diag(w).
Is there a faster method than this or is this the most efficient method?
(for small m,n there won't be any difference but if m,n are large creating a
diagonal matrix and multiplying might take time)
Thanks
Karthik
This is an alternative approach:
B = A .* repmat(w, size(A, 1), 1);
-Herbert
help spdiags. You can make a sparse diagonal matrix or you can use repmat.
When I have compared them, I think repmat was a little faster, but I still
prefer the sparse multiply for elegance. Both are considerably faster than
diag, which, as you have observed, does useless multiplies.