function CompareFuelConsumption
close all
data
[d,s] = xlsread('Inverter Generators.xls'); %#ok<NASGU> tankSize = d(6,:); %gal brandNames = {'Honda','Yamaha','other'}; brandNum = [3 1 1 1 1 2 2 2 2 3 3 3 3 3 3]; %see brandNames brandColors = [1 0 0; 0 0 1; 0 0 0]; %r,b,k power = d(3:4,:); %[peak; rated] runTime = d(7:9,:); %hours (see ratings) ratings = [0.25; 0.5; 1]; %rows of runTime
plots
figure(1), xlabel 'Peak Watts', ylabel kW-hrs/gal figure(2), xlabel 'Load (W)', ylabel kW-hrs/gal figure(3), xlabel 'Load (W)', ylabel hrs/gal ax = @(fig) findobj(fig,'type','axes'); set(ax(1:2),'box','on','xlim',[0 7000],'ylim',[0 10]) set(ax(3),'box','on','xlim',[0 7000],'ylim',[0 20]) hLines = cell(3,2); for k=1:3 %each brand brandCols = find(brandNum==k); timeArray = runTime(:,brandCols); tankArray = repmat(tankSize(brandCols),[3 1]); powerArray = ratings*power(2,brandCols); %outer product ratios = powerArray.*timeArray./tankArray; %kW-hrs/gal sizeArray = repmat(power(1,brandCols),[3 1]); hLines{k,1} = PlotBrandData(ax(1),sizeArray,ratios/1e3,brandColors(k,:)); hLines{k,2} = PlotBrandData(ax(2),powerArray,ratios/1e3,brandColors(k,:)); hLines{k,3} = PlotBrandData(ax(3),powerArray,ratios./powerArray,brandColors(k,:)); end % legends for fig=1:3 h = [hLines{1,fig}(1) hLines{2,fig}(1) hLines{3,fig}(1)]; hLegends(fig) = legend(h,brandNames); %#ok<AGROW> end
log-fit
set(ax(3),'xscale','log','yscale','log') set(ax(3),'xlim',[100 10000],'ylim',[1 100],'xgrid','on','ygrid','on') line([100 5000],[60 1],'color','g','LineWidth',2) delete(hLegends(3)) h = [hLines{1,3}(1) hLines{2,3}(1) hLines{3,3}(1)]; legend(h,brandNames)
end %main function hLines = PlotBrandData(ax,xData,yData,c) hLines = line(xData,yData,'LineWidth',2,'color',c,'parent',ax,... 'marker','o','MarkerSize',8,'MarkerEdgeColor',c); for idx=1:4 %each line h = hLines(idx); x = get(h,'xdata'); y = get(h,'ydata'); x(isnan(y)) = []; y(isnan(y)) = []; set(h,'xdata',x,'ydata',y) end end %PlotBrandData