File size: 1,876 Bytes
0c0a4be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
% Code to plot simulation results from Battery_Management_System
%% Plot Description:
%
% Copyright 2021-2026 The MathWorks, Inc.

% Generate new simulation results if they don't exist or if they need to be updated
if ~exist('simlog_Battery_Management_System', 'var') 
    sim('Battery_Management_System')
end

% Reuse figure if it exists, else create new figure
if ~exist('h1_Battery_Management_System', 'var') || ...
        ~isgraphics(h1_Battery_Management_System, 'figure')
    h1_Battery_Management_System = figure('Name', 'Battery_Management_System');
end
figure(h1_Battery_Management_System)
clf(h1_Battery_Management_System)

% Get simulation results
simlog_t=simlog_Battery_Management_System.DC.Current_Source.i.series.time;
simlog_I=simlog_Battery_Management_System.DC.Current_Source.i.series.values;
simlog_minSOC_error=Battery_Management_System_Scope{5}.Values.Data(:,1)...
                    -Battery_Management_System_Scope{5}.Values.Data(:,2);
simlog_maxSOC_error=Battery_Management_System_Scope{6}.Values.Data(:,1)...
                    -Battery_Management_System_Scope{6}.Values.Data(:,2);

% Plot results
simlog_handles(1) = subplot(3, 1, 1);
plot(simlog_t, simlog_I, 'LineWidth', 1)
title('Battery Pack Current')
ylabel('Current (A)')
xlabel('Time (s)')
%
simlog_handles(2) = subplot(3, 1, 2);
plot(simlog_t, abs(simlog_minSOC_error),'r')
title('Error in min. State of Charge (actual~prediction) prediction')
ylabel('actual~prediction')
xlabel('Time (s)')
ylim([-0.05 0.05])
%
simlog_handles(3) = subplot(3, 1, 3);
plot(simlog_t, abs(simlog_maxSOC_error),'r')
title('Error in max. State of Charge (actual~prediction) prediction')
ylabel('actual~prediction')
xlabel('Time (s)')
ylim([-0.05 0.05])

% Remove temporary variables
clear simlog_t simlog_SOC simlog_I simlog_minSOC_error simlog_maxSOC_error
clear simlog_handles Battery_Management_System_Scope