MATLAB: How to scale the columns of a large square matrix

matrix arraymatrix manipulationmemory

Let n be large, say 300,000. Let A be an n by n matrix, and v=[v1, v2, … , vn] be a vector of dimension n.
My goal is to scale each column of A according to the vector v. For example, column 1 of A is multiplied by v1, column 2 is multiplied by v2, etc.
One way to do this is to use matrix multiplication:
A*diag(v)
However, diag(v) requires too much memory since n is too big. Is there another way to achieve my goal without using diag(v)? Of course, I can use a for loop, but I guess that may be slow. I prefer to avoid using for loop if possible.

Best Answer

Let A be your m*n, and b be 1*n vector.
iwant = A.*b ;