One way to do it is as follows. Suppose the set of scalars are put
into a vector v. Then
diag(v) * M
effects this multiplication.
In my case, the problem is that constructing the diagonal matrix
diag(v) will exceed my computer memory. Obviously I could resort to a
loop, but I'm wondering if there is a different way to vectorize this
multiplication.
Thanks,
Jim
What is wrong with just using bsxfun for this? (I do not understand
why you have to make a new matrix for).
EDU>> A=[1 2 3;4 5 6;7 8 9]
1 2 3
4 5 6
7 8 9
EDU>> v=[1 2 3]'
1
2
3
EDU>> bsxfun(@times,v,A)
1 2 3
8 10 12
21 24 27
--Nasser
Or, you could use a sparse diagonal matrix instead of a full one
N=length(v);
spdiags(v(:),0,N,N)*M;
Thanks. There's nothing wrong with using bsxfun to do this. I was
unaware of that function, which is why I was posting. It works great.
Jim