-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathefficiencyGraph.m
More file actions
154 lines (137 loc) · 5.32 KB
/
efficiencyGraph.m
File metadata and controls
154 lines (137 loc) · 5.32 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
function graph = efficiencyGraph()
%% Description: the main script, an API, for obtaining an efficiency and capacity double y-axis graph
fileName = input('Which file do you want this script to read?\n\nInput the file name (quotation marks not necessary): ', 's');
sheet = input('Which sheet do you want this script to read?\nPlease enter the sheet number\n\nInput your answer: ');
includeCapacity = input('Would you like to include the charge/discharge capacities for every cycle? [Y/N]\nInput your answer here: ', 's');
if includeCapacity == 'Y' | includeCapacity == 'Y'
includeCapacity = true;
else
includeCapacity = false;
end
excludeThese = input('Which cycles do you wish to exclude from the data?\nYou can also leave this part blank and press "ENTER"\n\nInput your answer as a vector: ');
graph = getEfficiencyGraph(fileName, sheet, includeCapacity, excludeThese);
function graph = getEfficiencyGraph(fileName, sheet, includeCapacity, excludeThese)
%% Description: A function that will plot charge/discharge energies and efficiencies for various cycles
% Much of the logic that went into this script was also used in
% capacityVoltage.m, albeit much simpler to code overall.
%% INPUT %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% fileName = name of the .xls or .xlsx file containing data
%% sheet = name of sheet containing data at the start of every cycle
% Make sure the file contains all the cycles intended to be plotted.
%% excludeThese = cycles to be left out of the graph
%% FILTERING
[num, txt, raw] = xlsread(fileName, sheet);
% NUM is typical double array with numbers only, RAW is cell array that
% also includes text with no OFFSET
cycles = num (:, 1); % vector of cycle IDs
maxColLength = size(cycles, 1);
cycleIDind = find(cycles == cycles, maxColLength); % rows in NUM that indicate the start of a cycle
cycleIDind = cycleIDind + 3; % ADJUSTMENT rows in RAW that indicate start of a cycle
% it is assumed the offset is by default 3.
% cycleIDs = cycles;
%
% allNaN = find(isnan(cycleIDs));
% cycleIDs(allNaN) = [];
%% MAKING DATA POINTS
points = {};
% every point will have: {[cycleID, engy_chg, engy_dchg, efficiency]};
for k = 1:length(cycleIDind)
cycleID = raw{cycleIDind(k), 1};
engy_chg = raw{cycleIDind(k), 7};
engy_dchg = raw{cycleIDind(k), 8};
efficiency = raw{cycleIDind(k), 6};
% if the efficiency doesn't make sense, exclude the data point.
plotThis = {[cycleID engy_chg engy_dchg NaN]};
if efficiency < 100.000 && efficiency > 0.000
if ~any(ismember(excludeThese, cycleID))
plotThis = {[cycleID engy_chg engy_dchg efficiency]};
end
end
points{size(points, 1) + 1, 1} = plotThis;
end
%% GRAPHING
cycleIDs = [];
if includeCapacity
allChgEngy = [];
allDchgEngy = [];
end
allEfficiency = [];
for i = 1:length(points)
cycle = points{i}{1};
cycleIDs = [cycleIDs cycle(1)];
if includeCapacity
allChgEngy = [allChgEngy cycle(2)];
allDchgEngy = [allDchgEngy cycle(3)];
allEfficiency = [allEfficiency cycle(4)];
else
allEfficiency = [allEfficiency cycle(4)];
end
end
% outlier_chg_engy = isoutlier(allChgEngy);
% outlier_dchg_engy = isoutlier(allDchgEngy);
% for i = 1:length(excludeThese)
% ind = cycleIDs(cycleIDs == excludeThese(i));
% cycleIDs(ind) = nan;
% allChgEngy(ind) = nan;
% allDchgEngy(ind) = nan;
% allEfficiency(ind) = nan;
% end
% allNaNcyc = find(isnan(cycleIDs));
% cycleIDs(allNaNcyc) = [];
% allNaNchg = find(isnan(allChgEngy));
% allChgEngy(allNaNchg) = [];
% allNaNdchg = find(isnan(allDchgEngy));
% allDchgEngy(allNaNdchg) = [];
% allNaNeff = find(isnan(allEfficiency));
% allEfficiency(allNaNeff) = [];
% Additional Outlier point exclusion
% cycleIDs(outlier_chg_engy) = [];
% allChgEngy(outlier_chg_engy) = [];
% allDchgEngy(outlier_chg_engy) = [];
% allEfficiency(outlier_chg_engy) = [];
%
% cycleIDs(outlier_dchg_engy) = [];
% allChgEngy(outlier_dchg_engy) = [];
% allDchgEngy(outlier_dchg_engy) = [];
% allEfficiency(outlier_dchg_engy) = [];
% plot energies first
if includeCapacity
yyaxis left
plot(cycleIDs, allChgEngy, 'o-', 'LineWidth', 2,...
'MarkerSize', 8);
hold on
plot(cycleIDs, allDchgEngy, 'o--',...
'LineWidth', 2,...
'MarkerSize', 8);
hold on
ylabel('Capacity (mAh)','FontSize',20, 'FontWeight','bold');
xlabel ('Cycle','FontSize',20, 'FontWeight','bold');
% yticks(0.2:0.1:0.9);
hold on
% plot efficiency
yyaxis right
plot(cycleIDs, allEfficiency, '-o',...
'LineWidth', 2,...
'MarkerSize',8);
ylabel ('Coulombic Efficiency (%)', 'FontSize',20, 'FontWeight','bold');
% yticks(65:5:100);
hold on
a = get(gca,'XTickLabel');
set(gca,'XTickLabel',a,'fontsize',16)
set(gcf,'color','white')
% xticks(0:max(raw{:,1}));
legend('Charge', 'Discharge', 'Efficiency');
else
plot(cycleIDs, allEfficiency, '-o',...
'LineWidth', 2,...
'MarkerSize',8);
ylabel ('Coulombic Efficiency (%)', 'FontSize',20, 'FontWeight','bold');
% yticks(65:5:100);
hold on
a = get(gca,'XTickLabel');
set(gca,'XTickLabel',a,'fontsize',16)
set(gcf,'color','white')
% legend('Charge', 'Discharge', 'Efficiency');
xlabel ('Cycle','FontSize',20, 'FontWeight','bold');
end
graph = gcf;