From: Lisa on
In my simulations these loops need to be run through almost 200000 times. With my clumsy programming I estimate that this will take almost 20 days! I would really appreciate some help in vectorising and hopefully optimising this chunck of code (below)

Thanks!

%Y, A and O are matrices
%c and r are vectors
%d is scalar

for i = 1:final
d = SMALL_VALUE;
for j = 1:final
Y(i,j)=A(i,j)*r(j);
d = d + Y(i,j);
end
for j = 1:final
O(i,j) = (c(i)/d) * Y(i,j);
end
end
for j = 1:final
d = SMALL_VALUE;
for i =1:final
d = d + (A(i,j)*r(j) - O(i,j))* A(i,j);
end
r(j)= r(j) - d/p(j);
end