Alright so I was able to finish this myself, here is the code for anyone else who comes across this and might have ways to improve it.
- Main problem is in the while loop, shift1/2/3 change size with every loop, which will slow down the program over time and as data set gets bigger (no fix as of yet)
%initializing the data and sorting it by date then shift
%FUTURE CHANGES -- change the format so that it doesn't have to rewrite shit1-3
%as this can cause slow speeds of processing
wt136 = sortrows(xlsread('Waste Tracking.xlsx', '3131-136'),[1 2]);
wt134 = sortrows(xlsread('Waste Tracking.xlsx', '3121-134'),[1 2]);
wt122 = sortrows(xlsread('Waste Tracking.xlsx', '4561-122'),[1 2]);
wtevol = sortrows(xlsread('Waste Tracking.xlsx', 'EVOL'),[1 2]);
wtdro = sortrows(xlsread('Waste Tracking.xlsx', 'DRO'),[1 2]);
wtcorr = sortrows(xlsread('Waste Tracking.xlsx', 'Corrugator'),[1 2]);
names = sheetnames('Waste Tracking.xlsx');
for z = 1:6
index = 1;
index2 = 1;
shift1 = [];
shift2 = [];
shift3 = [];
s1i = 1;
s2i = 1;
s3i = 1;
if z == 1
a = wt136;
elseif z == 2
a = wt136;
elseif z == 3
a = wt122;
elseif z == 4
a = wtevol;
elseif z ==5
a = wtdro;
else
a = wtcorr;
end
shift1T = zeros(length(a(:,1)),2);
shift2T = zeros(length(a(:,1)),2);
shift3T = zeros(length(a(:,1)),2);
while(~isnan(a(index)))
phold = a(index,1);
phold2 = phold;
while(phold2 == phold)
if a(index,2) == 1 %adding together the total for the day for each shift
shift1(s1i) = (a(index,5));
s1i = s1i +1;
elseif a(index,2) == 2
shift2(s2i) = (a(index,5));
s2i = s2i +1;
elseif a(index,2) == 3
shift3(s3i) = (a(index,5));
s3i = s3i +1;
end
index = index +1;%increasing index of data value in spreadsheet
phold2 = a(index,1);
end
shift1T(index2,:) = [a(index-1,1),sum(shift1)];
shift2T(index2,:) = [a(index-1,1),sum(shift2)];
shift3T(index2,:) = [a(index-1,1),sum(shift3)];
shift1 = [];%reseting back to 0 so that days don't add together
shift2 = [];
shift3 = [];
index2 = index2 +1;
end
%this gets rid of unnessesary 0 columns in the data
shift1T = shift1T(~all(shift1T == 0, 2),:);
shift2T = shift2T(~all(shift2T == 0, 2),:);
shift3T = shift3T(~all(shift3T == 0, 2),:);
%converting date numbers to dates, gets the first and last date
d1 = datetime(shift1T(1,1), 'ConvertFrom', 'datenum', 'Format', 'MM-dd-yy');
c = length(shift1T(:,1));
d2 = datetime(shift1T(c,1), 'ConvertFrom', 'datenum', 'Format', 'MM-dd-yy');
d = d1:d2;
%PLOTTING TIME
figure(z);
grid on
hold on
plot(d,shift1T(:,2), '-s');
plot(d,shift2T(:,2),'-s');
plot(d,shift3T(:,2), '-s');
xlabel("Date");
ylabel("Waste (lbs)");
title("Waste per Day per Shift for "+names(z+1)+"");
legend('Shift 1', 'Shift 2', 'Shift 3', 'Location', 'northwest');
end
