My program reads data from a file column 1 is an ID number, column 2 is a weight, column 3 is the priority. Supplies must be loaded on to a ship (capacity 60 tons) by priority.
On the second for loop I would like to start the loop where my computed ID's end (not 1). (So i can search for the remaining weight needed by priority without finding an ID that i already have).
With that being said, any other advice to make my code more efficient would be greatly appreciated.
function [] = Supplies(filename)
A = load('data1.txt');
A = sortrows(A,-3);
tons = 0;
tonsN=0;
ID = zeros(1);
cnt =1;
for i = 1:1000
if (tons < 60)
tonsN = A(i,2);
tons = tons + tonsN;
ID(cnt) = [ A(i,1)];
cnt = cnt+1;
else
ID(end)=[];
tons = tons - tonsN;
break
end
end
tonsNEED = 60-tons;
tons
tonsNEED
for i = 1:1000
if A(i,2) == tonsNEED
ID(end+1) = A(i,1);
break
end
end
disp(ID')
end