Plot multiple plots on the same graph

13 views (last 30 days)
DIP
DIP on 14 Mar 2018
Answered: ND on 22 Jun 2018
Hi ,
I wish to plot these graphs as a function of Tpack % Temperature of battery pack. There are two temperatures , Tpack = [289 273].
Full code here :
%%ME 836 - HW5 Problem 4
clear;close all;clc;
HW5_Constants;
% Data provided in excel files to interpolate the bsfc
Eta_mValues = 'motoreff.csv';
TorqueValues = 'Warp9Torquey.csv';
RPMValues = 'Warp9RPMx.csv';
Eta_m_val= csvread(Eta_mValues);
torque_val= csvread(TorqueValues);
speed_val= csvread(RPMValues);
%%Battery details
SOC = zeros; Ah = zeros; VDC_total = zeros; t = zeros;
Time = zeros; Wh = zeros;
%%With Grade 10 mph Headwind, 30 psi tire pressure
Vehicle_Speed = 40;
i = 1;
dt = 1; % Time interval
t = 0; % Initial time
P_motor = 35868; % Motor power
n = 10; % Number of batteries
SoC_new = 1; % Initial state of charge
VDC_total = 129; % Initial pack voltage
Bat_Wh = 14190; % Initial watt hours
Cr = 110; % Initial battery capacity
Tpack = [298 273]; % Temperature of battery pack
m = 1;
for m =1:2
for i=1:41
% Vehicle speed
VMPH(i) = Vehicle_Speed; % mph
Vmps(i) = Vehicle_Speed*0.44704; % m/s
%Effective Velocity
Veff_MPH(i) = VMPH(i)+(Vhead*phi_head); % mph
Veff_mps(i) = Veff_MPH(i)*0.44704; % m/s
% Rolling resistance force (N)
Fr(i) = (p_tire/pref)^(alpha)*(Vwt/zref)^(beta)*(ar+(br*Vmps(i))+(cr*Vmps(i)^2));
% Gradient force
Fg(i) = Vm*g*sind(1);
% Frontal area (m2)
Af = 0.84*Vht*Vwd;
% Air density (kg/m3)
rho = Pamb/R/Tamb;
% Aerodynamic drag (N)
Fd(i) = 0.5*rho*Af*Cd*(Veff_mps(i))^2;
% Tractive force (N)
Ft(i) = Fd(i)+Fr(i)+Fg(i);
% Torque at the wheels (Nm)
Tao_w(i) = Ft(i)*Dt/2;
% Brake torque (Nm)
Tao_brake(i) = Tao_w(i)/io/ig/etadr;
Tao_b(i) = Tao_brake(i)*0.73756; % Tao_brake -- lbf.ft
% Engine speed (rpm)
N(i) = Vmps(i)*io*ig/pi/Dt*60;
% Brake power (kW)
Pb(i) = 2*pi*Tao_brake(i)*N(i)/60/1000;
% Efficency of motor
Eta_m(i) = interp2(speed_val,torque_val,Eta_m_val,N(i),Tao_b(i));
Eff(i) = Eta_m(i)/100;
% Power from battery pack
Pow_Bat(i) = Pb(i)/Eff(i);
%Power from battery back in watt hours
Pow_Battery(i) = Pow_Bat(i)*1000;
% Initialize variables for while loop
t=0; dt=1; k=1;
SoC_new = 1; % Initial values of SoC
VDCInitial = 129; % Battery pack voltage
Wh = Bat_Wh; % Wh
Cr= 110; % Battery Capacity
%Iterative loop for VDCPack and Time
while SoC_new >= 0.2 % Actual SoC
Wh = Wh -(Pow_Battery(i)*dt/3600); % Wh
It_Ah = Pow_Battery(i)/VDCInitial; % Battery current
del_c = gamma*((It_Ah/Iref)^(chi))*((Tref/Tpack(m))^(delta))*dt/3600;
Cr = Cr - del_c; % Battery capacity
SoC_new = Cr/110; % Updated value of SoC
VDC_updated=(1.3*SoC_new+11.6)*n; % Updated values of pack voltage
VDCInitial=VDC_updated;
k=k+1;
t = t + dt;
end
% Store while loop values for the for 'for' loop
Watt_hr(i) = Wh; SoC(i) = SoC_new;
% Plotting values
kWh_used(i) = (Bat_Wh-Watt_hr(i))/1000; % Used kWh
Time(i)=t; % Time
Dist(i) = Time(i).*VMPH(i)/3600; % Distance covered
MPGe(i) = Dist(i)*33.705/kWh_used(i); % Miles per gallon equivalent
MPG_gas(i) = kWh_used(i)*1000/33705; % Miles per gallon for gasoline
Vehicle_Speed=Vehicle_Speed+1; % Update vehicle speed
end
% Plots
figure('units','normalized','Position',[0.1 0.1 0.7 0.7])
subplot(2,3,1)
plot(VMPH,kWh_used,'b','LineWidth',2)
axis([40 80 6.5 10.5])
title('Battery KWh Used vs. Highway Speed','FontSize',12)
xlabel('Highway Velocity [mph]','FontSize',10)
ylabel('Kilowatt-Hours Used [kWh]','FontSize',10)
legend('T = 298 K','T = 273 K','Location','northeast')
subplot(2,3,2)
plot(VMPH,Dist,':r','LineWidth',2)
axis([40 80 10 35])
title('Range of EV vs. Highway Speed','FontSize',12)
xlabel('Highway Velocity [mph]','FontSize',10)
ylabel('Distance Travelled [mi]','FontSize',10)
legend('T = 298 K','T = 273 K','Location','northeast')
subplot(2,3,3)
plot(VMPH,MPGe,'--g','LineWidth',2)
axis([40 80 50 110])
title('Equivalent Fuel Economy vs. Highway Speed','FontSize',12)
xlabel('Highway Velocity [mph]','FontSize',10)
ylabel('MPGe','FontSize',10)
subplot(2,3,4)
plot(VMPH,Eta_m,'--y','LineWidth',2)
axis([40 80 87 95])
title('Motor Efficiency vs. Highway Speed','FontSize',12)
xlabel('Highway Velocity [mph]','FontSize',10)
ylabel('Motor Efficiency [%]','FontSize',10)
subplot(2,3,5)
plot(VMPH,Pow_Bat,':r',VMPH,Pb,'b','LineWidth',2)
axis([40 80 10 50])
title('Power Required/Supplied vs. Highway Speed','FontSize',12)
xlabel('Highway Velocity [mph]','FontSize',10)
ylabel('Power [kW]','FontSize',10)
legend('Motor Power','Brake Power','Location','northwest')
subplot(2,3,6)
plot(VMPH,MPG_gas,'r','LineWidth',2)
axis([40 80 0.18 0.32])
title('Equivalent Gasoline Used vs. Highway Speed','FontSize',12)
xlabel('Highway Velocity [mph]','FontSize',10)
ylabel('Equivalent Gasoline [gal]','FontSize',10)
end

Answers (2)

Venkata Siva Krishna Madala
Hello DIP,
I understand that you want all the plots to be combined into a single plot. This can be done as shown below.
plot(VMPH,kWh_used,'b',VMPH,Dist,':r',VMPH,MPGe,'--g',VMPH,Eta_m,'--y',VMPH,Pow_Bat,'--r',VMPH,MPG_gas,'k')
Regards,
Krishna Madala
  1 Comment
Venkata Siva Krishna Madala
You can also insert a Legend for the different lines on the plot using the legends function.

Sign in to comment.


ND
ND on 22 Jun 2018
Can you please send full code with input file, I need this evulation file for my project, please share if possible inculding all input parameters.
Thank you.

Categories

Find more on Two y-axis 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!