Prev: iterative convergence technique for kinematic solution
Next: Synchronized crosshairs over multiple figures
From: Alfredo Rojas on 1 Jun 2010 17:57 Hello, I have to multiply each row of a matrix by a scalar contained in a vector, it's somthing like this a=rand(3,7); b=(1:7); for i=1:7 a(:,i)=a(:,i).*b(i) end I have to do something like this but with very large data in a simulation so the "for" makes it last so long, so, How avoid it?
From: Walter Roberson on 1 Jun 2010 18:21
Alfredo Rojas wrote: > > Hello, I have to multiply each row of a matrix by a scalar contained in > a vector, it's somthing like this > > a=rand(3,7); > b=(1:7); > for i=1:7 > a(:,i)=a(:,i).*b(i) > end > > I have to do something like this but with very large data in a > simulation so the "for" makes it last so long, so, How avoid it? I don't know if you will be able to get faster, but you could use a = bsxfun(@times, a, b); |