Adding legend of different names in a plot generated by a for loop
显示 更早的评论

I am performing Data Analysis for calenderic tests in various batteries. The various cell names are stored in M5BAT.CellList folder. I plot the graph for two different temperature ranges as shown below. I want to include the legend as the cell name or number chosen for different temperatures for every graph. close all clear all load('M5BAT_analysis_all.mat') plottype = 3;
%General constants
%MAXCYC = 30000;
MAXSOH = 103;
%MINSOH = 95;
MINSOH = 10;
Colour = colormap(jet(8));
Temp = [25 50];
CyclingDepth = [100 50 10 2];
CurrentRate = [0.75 1];
% Constants for different calendric test options
Cal.Num = [1:9];
Cal.Temp = [50 50 25 25 50 50 50 50 50];
Cal.SoC = [10 50 50 50 30 50 50 80 100];
% Set up a List where the direct pointers to all elements are stored
% for calendric Cells
for i=1:size(Cal.Num, 2)
for j=1:size(M5BAT.CellList, 2)
if M5BAT.CellList(j).Number == Cal.Num(i)
Cal.Index(i) = j; % Cal.Index = 1 2 3 4 5 6 7 8 9
end
end
end
for i=1:2 % it loops for different temperatures, 1 for 25 degree and for both 25 and 50 degree Celsius
% Go Through the two differnet temperatures
Index = find(Cal.Temp == Temp(i));
subplot(1, 3, i); % Definition of the subplot (three subplot in this case)
for j=1:size(Index, 2)
%sort dates
d = 0; %initiation
for d=1:size(M5BAT.CellList(Cal.Index(Index(j))).ResultList,2)% gives the number of cells corresponding to
% that particular temperature
DateVec(d) = M5BAT.CellList(Cal.Index(Index(j))).ResultList(d).Sort; %converts date and time to vector
CrealVec(d)= M5BAT.CellList(Cal.Index(Index(j))).ResultList(d).Creal10;
%DateVec_1(d) = M5BAT.CellList(Cal.Index(Index(j))).ResultList(d).Sort;
%CrealVec_1(d)= M5BAT.CellList(Cal.Index(Index(j))).ResultList(d).Creal10;
%DateVec_2(d) = M5BAT.CellList(Cal.Index(Index(j-2))).ResultList(d).Sort;
%CrealVec_2(d)= M5BAT.CellList(Cal.Index(Index(j-2))).ResultList(d).Creal10;
end
%calculate days in between checkups and capacity
for k=1:size(M5BAT.CellList(Cal.Index(Index(j))).ResultList,2)
XValue(k) = DateVec(k) - DateVec(1); %storage days
YValue(k) = CrealVec(k) / CrealVec(1) * 100; %capacity
end
if d > 0
plot(XValue , YValue, '-xb', 'Color', Colour(ceil(j),:), 'LineWidth', 2, 'MarkerSize', 8);
hold on;
% legendInfo {j}= ['Cell.number='{M5BAT.CellList(j).result}];
% legend(legendInfo));
clear XValue YValue;
end
end
axis([0 150 85 103]);
grid on;
xlabel('Storage Time / in Days');
ylabel('Capacity / in %');
% legend(['Cell.number = ' num2str(M5BAT.CellList(Index(j)))]);
title(['Ageing at ' num2str(Temp(i)) '°C']);
legendInfo{j}=(['Cell.name = ' num2str(j)]);
legend(legendInfo);
% for p=1:size(M5BAT.CellList(Cal.Index(Index(j))).ResultList,2);
% legendInfo{p}= ['Cell.number = ', {p}];
% legend(legendInfo)
%end
end
I tried using legendInfo but it is not working. I will be grateful for any help regarding this. I have attached the plot for this code. I want to include the name of different cells considered for that particular temperature. Please help me about how i could do that. Thanks in advance!
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 App Building 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

