I am trying to solve an LP using bintprog and have constructed all the contraints using for loops. However, this makes the process too slow so I want to write all of my loops in vectorized code but I am having trouble doing this. Here are some of the loops that i want to vectorize:
A=zeros(J,J)
for i=1:J
A(i,i)=1;
end
B=zeros(((J-20)*20)+sum(1:19),J);
for q=1:J-1
for k=1:q
for i=1:J-q
B(i,i+k)=1;
B(i,k)=1;
end
end
end
for the first case, J=42
Can anybody help me to understand how to vectorize these? I have looked at lots of information about matlab vectorization online and haven't managed to find anything which will help.