MATLAB: For loop doesn’t seem to loop

for looplinprogloopingoptimization

Hi I have the following code
for i = 1:8760
A = [PVtech(i,:) WTtech(i,:)];
b = demand(i);
f = [CRF*PVtechcost(i,:).*PVcap(i,:)./PVtech(i,:) CRF*WTtechcost(i,:).*WTcap(i,:)./WTtech(i,:)];
x(i) = linprog(f, A,b,[], [], lb);
end
I am trying to optimise linprog over the 8760 data set but I can't seem to get the loop going for each row. therefore when I run it is get a size of A to be 1×30 (when it should be 8760 by 30) Does anyone see where I have coded wrongly ?
thank you

Best Answer

You're not specifying the row of A that you are writing the data to, so each loop it just places [PVtech(i,:) WTtech(i,:)] into the first row of A.
Try:
for m = 1:8760
A(m,:) = [PVtech(m,:) WTtech(m,:)];
b = demand(m);
f = [CRF*PVtechcost(m,:).*PVcap(m,:)./PVtech(m,:) CRF*WTtechcost(m,:).*WTcap(m,:)./WTtech(m,:)];
x(m) = linprog(f, A,b,[], [], lb);
end