How to plot multiple plots in a for loop without overwriting them?
Show older comments
Hello all,
I have been striving to plot the irradiance vector and its corresponding impact over the SOC of the battery, but it seems to be writing the same over and over till the end of the loop, for this case I only set up a 2 for loop.
It is as if it will not load the following corresponding value and make up the second plot with the same older value. The problem arise on figure 1 and 2, do you have any workaround for this matter?

This is the code.
%To simulate the 12 months at one click
close all;
clear;
tic %%%%Mido el tiempo de ejecución
load PED_HDW_GEO_5.mat
%%%%%%%%Storage of variables for each iteration%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
month_=zeros(12,1);
Irr_=zeros(12,1);
SOC_=zeros(12,1);
%%%Here I execute the code twice
for month_number=1:2
if (month_number>=1) && (month_number<=2)
Season=1.30; %%C
else
Season=1.20;
end
%%%SIMULINK model
sim('Full_D_.slx');
disp(month_number)
bdclose('Full_PED_FL.slx');
%%%%Data upload
load month.mat
load Irr.mat
load SOC.mat
%%%%%%time base
Irr.time=Irr.time/3600;
T=Irr.time;
%%%
figure(1)
plot(T, SOC.data);
hold on
grid on
xlim([8 32])
ylabel('SOC (%)', 'FontSize',14)
xlabel('Hours (day)', 'FontSize',14)
title('SOC along the year variation', 'FontSize',14)
% % % saveas(gcf,'_SOC_alongYear.png')
figure(2)
plot(T, Irr.data)
hold on
grid on
xlim([8 32])
xlabel('Hours', 'FontSize',14)
ylabel('Irradiance (W·m²)', 'FontSize',14)
title('Irradiance along year', 'FontSize',14)
SOC= (min(SOC))*100;
I=max(Irr);
% % % % All of the accumulated variables in the for loop
month_(month_number)=month_number;
Irr_(month_number)=I;
SOC_(month_number)=SOC;
end
figure (1)
legend('Jan','Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')
figure (2)
legend('Jan','Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec')
Accepted Answer
More Answers (0)
Categories
Find more on Deep Learning Toolbox 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!
