Help with plotting data in a mat file
Show older comments
Hi, I have series of data that I need to plot, however, the sum is not working properly, the values are not correct. Attached is my code.
for i=1:1:30
F = "Fuel";
E = "Emissions";
P = "Power";
R = "RPM";
CO = "CO_2";
SO = "SOx";
NO = "NOx";
Q = int2str(i);
if i ==27 || i == 1 || i == 2 || i ==3
else
%% Fuel consumption
A(i) = load(append(F,Q)); % Load Fuel Data
B(i)= sum(A(i).Fuel(2,:)); % Sum Daily Fuel Data
G(i) = B(i)/24; % Daily Fuel / Hr
C = sum(B); % Total fuel Consumption in a month
D = C/26; % Average Fuel Consumption in a month
Z = sum(G)/26; % Daily Average Fuel / Hr
%% Emissions
A1(i) = load(append(E,Q)); % Load Emission Data
B1(i)= sum(A1(i).Emissions(2,:)); % Sum Daily Fuel Data
G1(i) = B1(i)/24; % Daily Emission / Hr
C1 = sum(B1); % Total Emission in a month
D1 = C1/26; % Average Emission in a month
Z1 = sum(G1)/26; % Daily Emission / Hr
%% Power
A2(i) = load(append(P,Q)); % Load Power Data
B2(i)= 2*0.25*sum(A2(i).Power(2,:)); % Sum Daily Fuel Data
G2(i) = B2(i)/24; % Daily Average / Hr
C2 = sum(B2); % Total Power in a month
D2 = C2/26; % Average Power in a month
Z2 = sum(G2)/26; %Daily Power / Hr
%% RPM
A3(i) = load(append(R,Q)); % Load Rpm Data
B3(i)= sum(A3(i).RPM(2,:)); % Sum Daily rpm Data
C3 = sum(B3); % Total rpm Data in a mont
D3 = C3/26; % Average rpm in a month
%% NOX EMISSION
A4(i) = load(append(NO,Q)); % Load Fuel Data
B4(i)= sum(A4(i).NOx(2,:)); % Sum Daily Fuel Data
G4(i) = B4(i)/24; % Daily Fuel / Hr
C4 = sum(B4); % Total fuel Consumption in a month
D4 = C4/26; % Average Fuel Consumption in a month
Z4 = sum(G4)/26; % Daily Average Fuel / Hr
%
%% SOX EMISSION
A5(i) = load(append(SO,Q)); % Load Fuel Data
B5(i)= sum(A5(i).SOx(2,:)); % Sum Daily Fuel Data
G5(i) = B5(i)/24; % Daily Fuel / Hr
C5 = sum(B5); % Total fuel Consumption in a month
D5 = C5/26; % Average Fuel Consumption in a month
Z5 = sum(G5)/26; % Daily Average Fuel / Hr
%
%% CO2 EMISSION
A6(i) = load(append(CO,Q)); % Load Fuel Data
B6(i)= sum(A6(i).CO2(2,:)) % Sum Daily Fuel Data
G6(i) = B6(i)/24; % Daily Fuel / Hr
C6 = sum(B6); % Total fuel Consumption in a month
D6 = C6/26; % Average Fuel Consumption in a month
Z6 = sum(G6)/26; % Daily Average Fuel / Hr
end
end
figure(1)
subplot(2,3,1)
yline(D,'r')
hold on
bar(B,'b')
xlabel ('Days of the Month');
ylabel ('Fuel Consumption (Kg)')
title('Daily Fuel consumption of marine diesel engine')
legend('Average Fuel','Daily Fuel')
grid on
subplot(2,3,2)
yline(D1,'r')
hold on
bar(B1,'b')
xlabel ('Days of the Month');
ylabel ('Emissions (Kg)')
title('Daily Emission of marine diesel engine')
legend('Average Emission','Daily Emission')
grid on
subplot(2,3,3)
yline(D2,'r')
hold on
bar(B2,'b')
xlabel ('Days of the Month');
ylabel ('Power (KWh)')
title('Daily Average load of marine diesel engine')
legend('Average load','Daily Power')
grid on
t = annotation('textbox', [0.44, 0.40, 0.1, 0.1], 'String', "SIMULATION SUMMARY");
t.FontSize = 16;
t.FontWeight ='bold';
t.LineWidth = 2;
t.Color = 'r';
t.EdgeColor = 'r';
annotation('textbox', [0.15, 0.30, 0.1, 0.1], 'String', "Total Fuel Consumption = " + C + " Kg ")
annotation('textbox', [0.15, 0.20, 0.1, 0.1], 'String', "Average Fuel Consumption = " + D + " Kg ")
annotation('textbox', [0.45, 0.30, 0.1, 0.1], 'String', "Total NOX Emission = " + C4 + " Kg ")
annotation('textbox', [0.45, 0.25, 0.1, 0.1], 'String', "Total SOX Emission = " + C5 + " Kg ")
annotation('textbox', [0.45, 0.20, 0.1, 0.1], 'String', "Total CO_2 Emission = " + C6 + " Kg ")
annotation('textbox', [0.45, 0.15, 0.1, 0.1], 'String', "Total Emission = " + C1 + " Kg ")
annotation('textbox', [0.45, 0.10, 0.1, 0.1], 'String', "Average Emission = " + D1 + " Kg ")
annotation('textbox', [0.73, 0.30, 0.1, 0.1], 'String', "Daily Average Power = " + sum(G2)+" Kwh")
2 Comments
Cris LaPierre
on 17 Jun 2021
A quick check appears to show that it is calculating a sum. Which sums are incorrect? What should the correct values be?
chizom wornu
on 17 Jun 2021
Edited: chizom wornu
on 17 Jun 2021
Accepted Answer
More Answers (0)
Categories
Find more on Switches and Breakers in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!