I have a long MATLAB code which takes a lot of time due to numerous for loops. I try to eliminate them but it looks like I do not understand the vectorization concept. To be more specific, consider the following simple example with two vectors with different sizes:
a1=[1 2];
a2=[1 2 3];
I want to computea1/a2 in a "piece-wise" sense. For that, I use the following for loops
div=0;
for i=1:size(a1,2)
for j=1:size(a2,2)
div=div+a1(i)/a2(j);
end
end
How can I vectorize such two for loops? Many thanks!