I am trying to improve the performance of my code by converting some iterations into matrix operations in Matlab. One of these is the following code and I need to figure out how can I avoid using loop in the operation.
Here gamma_ic & bow are two dimensional matrices. c & z are variables set from outer iterations.
for z=1:maxNumber,
for c=1:K,
n = 0;
for y2=1:number_documents,
n = n+(gamma_ic(y2,c)*bow(y2,z));
end
mu(z,c) = n / 2.3;
end
end
Appreciate your assistance.
Edit. Added The loop for c and z. The iteration goes on till the maximum indices in gamma_ic & bow. Added mu which is another two dimensional matrix to show usage of n.
candziterate through all possible indices forgamma_icandbowrespectively? I think it is worth showing how they iterate, and how you are usingn. Also any thoughts or understanding you have about vectorisation (it may be easy or hard to vectorise your code, but it would be good to understand what is blocking you and try to fix that)candz, we might be able to help to get rid of those loops too. But for the given code, you could try out -n = sum(gamma_ic(1:number_documents,c).*bow(1:number_documents,z))maxNumberandK?