What I want to calculate is as follows:
clc,clear allna = 1000;nb = 500;B = sprandn(na, nb, 0.1);C = sprandn(na, nb, 0.1);tic;for i = 1:500 a = rand(na, 1); results = (a.*B)'*C;endtoc;
I think you find it very simple.
But it takes quite long time for finishing these calculations. (In my original code, sizes of the matrix are much bigger and more for-loop iterations should be run.)
As you can see, vector {a} is changed in every iteration whereas the matrix [B] and [C] are constant in the for-loop.
But, matrix [B] and [C] are multiplied to the vector {a} every single time in the for-loop.
I'd like to pre-calculate a matrix related to the matrix [B] and [C] before starting the for-loop to avoid multipling the matrix [B] and [C] to the vector {a} repetitively.
But, I have no idea..
Best Answer