In: Computer Science
% Let's assume the file names File1,File2,File3 and File4 has engine speed, torque, emission data respectively for engine 1,2,3 and 4 in continuous columns. The matlab code to import the same will be as follows:
enginespeed1=xlsread(‘File1.xls’, 'A:A')
enginespeed2=xlsread(‘File2.xls’, 'A:A')
enginespeed3=xlsread(‘File3.xls’, 'A:A')
enginespeed4=xlsread(‘File4.xls’, 'A:A')
torque1=xlsread(‘File1.xls’, 'B:B')
torque2=xlsread(‘File2.xls’, 'B:B')
torque3=xlsread(‘File3.xls’, 'B:B')
torque4=xlsread(‘File4.xls’, 'B:B')
NOx1=xlsread(‘File1.xls’, 'C:C')
NOx2=xlsread(‘File2.xls’, 'C:C')
NOx3=xlsread(‘File3.xls’, 'C:C')
NOx4=xlsread(‘File4.xls’, 'C:C')
CO1=xlsread(‘File1.xls’, 'D:D')
CO2=xlsread(‘File2.xls’, 'D:D')
CO3=xlsread(‘File3.xls’, 'D:D')
CO4=xlsread(‘File4.xls’, 'D:D')
CO2_1=xlsread(‘File1.xls’, 'E:E')
CO2_2=xlsread(‘File2.xls’, 'E:E')
CO2_3=xlsread(‘File3.xls’, 'E:E')
CO2_4=xlsread(‘File4.xls’, 'E:E')
time1=xlsread(‘File1.xls’, 'F:F')
time2=xlsread(‘File2.xls’, 'F:F')
time3=xlsread(‘File3.xls’, 'F:F')
time4=xlsread(‘File4.xls’, 'F:F')
% Assuming variables enginespeed and time has the data of enginespeed versus time for every engine.
Plot(enginespeed1,time1)
hold on % hold on function helps in plotting data on same graph until hold off is used.
Plot(enginespeed2,time2)
Plot(enginespeed3,time3)
Plot(enginespeed4,time4)
legend('engine1', 'engine2', 'engine3', 'engine4') % create legends against each plot on graph
hold off
Plot(torque1,time1)
hold on
Plot(torque2,time2)
Plot(torque3,time3)
Plot(torque4,time4)
legend('engine1', 'engine2', 'engine3', 'engine4')
% Let's find maximum speed & torque for every engine against the time it happened
MaxSpeed_Eng1=max(enginespeed1)
MaxTorque_Eng1=max(torque1)
for i=1:length(enginepeed1)
if enginespeed1(i)==MaxSpeed_Eng1
T1=time1(i) % Time at which max speed happens
end
MaxSpeed_Eng2=max(enginespeed2)
MaxTorque_Eng2=max(torque2)
for i=1:length(enginepeed2)
if enginespeed2(i)==MaxSpeed_Eng2
T2=time2(i) % Time at which max speed happens
end
MaxSpeed_Eng3=max(enginespeed3)
MaxTorque_Eng3=max(torque3)
for i=1:length(enginepeed3)
if enginespeed3(i)==MaxSpeed_Eng3
T3=time3(i) % Time at which max speed happens
end
MaxSpeed_Eng4=max(enginespeed4)
MaxTorque_Eng4=max(torque4)
for i=1:length(enginepeed4)
if enginespeed4(i)==MaxSpeed_Eng4
T4=time4(i) % Time at which max speed happens
end
%Average of NOx & CO2 emissions
For i=1:length(NOx1)
Emi1(i)=NOx1(i)+CO2_1(i)
end
Avg_Emi_1=mean(Emi1) % Average emission of Engine1
For i=1:length(NOx2)
Emi2(i)=NOx2(i)+CO2_2(i)
end
Avg_Emi_2=mean(Emi2) % Average emission of Engine2
For i=1:length(NOx3)
Emi3(i)=NOx3(i)+CO2_3(i)
end
Avg_Emi_3=mean(Emi3) %Average emission of Engine3
For i=1:length(NOx4)
Emi4(i)=NOx4(i)+CO2_4(i)
end
Avg_Emi_4=mean(Emi4) % Average emission of Engine4
%Emission plot against all 4 engines
Plot(CO1,time1)
Plot(NOx1,time1)
Plot(CO2_1,time1)
Plot(CO2,time2)
Plot(NOx2,time2)
Plot(CO2_2,time2)
Plot(CO3,time3)
Plot(NOx3,time3)
Plot(CO2_3,time3)
Plot(CO4,time4)
Plot(NOx4,time4)
Plot(CO2_4,time4)
%Horsepower is calculated as =torque*enginespeed/5252
HP1=(torque1.*enginespeed1)./5252
HP2=(torque2.*enginespeed2)./5252
HP3=(torque3.*enginespeed3)./5252
HP4=(torque1.*enginespeed4)./5252
%Plot of HP, torque against time for all engines
Plot(time1,HP1)
hold on % hold on function helps in plotting data on same graph until hold off is used.
Plot(time1,torque1)
hold off
Plot(time2,HP2)
hold on % hold on function helps in plotting data on same graph until hold off is used.
Plot(time2,torque2)
hold off
Plot(time3,HP3)
hold on % hold on function helps in plotting data on same graph until hold off is used.
Plot(time3,torque3)
hold off
Plot(time4,HP4)
hold on % hold on function helps in plotting data on same graph until hold off is used.
Plot(time4,torque4)
hold off
%The engine with minimum emissions and maximum horsepower shall be recommended.