How to get a continuous load output of 7 days in one graph using loops
1 次查看(过去 30 天)
显示 更早的评论
Hi,
I am curently facing difficulty regarding generating a graph from a loop.
I am working on the daily EV load profile and have already got the daily load required for a day. I also got the output graph. However, this is for 24 hours. I want to get an output for 7 days. I used my previous loop(for daily load) in another loop to get it for 7 days or 168 hours, but I only got it as separtae graphs. I wanted it to show a continous output for 7 days straight. I tried changing the interval from 1440 minutes to 10080 minutes, but the loop takes the whole interval time and prvides a similar graph as the daily load output.
I want an output like the picture provided:
for day=1:7
i = 1;
distance_b = zeros(samples,1);
SOC_arrival_work_b = zeros(samples,1);
SOC_arrival_home_b = zeros(samples,1);
chargingstart_b = zeros(samples,1);
chargingstart_minute_b = zeros(samples,1);
charging_energy_b = zeros(samples,1);
duration_charge_b = zeros(samples,1);
intervals_charge_b = zeros(samples,1);
power_matrix_b = zeros(intervals,samples);
while i <= samples
% Randomly sample a driving distance from lognormal PDF
repeat_distance = 1;
while repeat_distance == 1
distance_b(i) = lognrnd(mu_d,sigma_d);
% Ensure it lies within range of upper bound from distance data
if distance_b(i) < range_UK(end)
repeat_distance = 0;
end
end
% Use distance to calculate SOC at arrival to work
SOC_arrival_work_b(i) = 1 - (distance_b(i)/max_range);
% Use same distance to calculate SOC at arrival home
SOC_arrival_home_b(i) = SOC_arrival_work_b(i) - (distance_b(i)/max_range);
% Randomly sample home arrival time/initial charging time from normal PDF
repeat_time = 1;
while repeat_time == 1
chargingstart_b(i) = normrnd(mu_chargingstart_b,sigma_chargingstart_b);
% Fix time after 24
if chargingstart_b(i) >= 0 && chargingstart_b(i) < 24
repeat_time = 0;
end
% Convert charging time to minute of day, [0 1440] minutes
% rounding if necessary
chargingstart_minute_b(i) = round((chargingstart_b(i)*(intervals/24)),0);
end
% Use sampled initial SOC from driving distance to determine required
% charging energy (kWh) to reach a full charge
charging_energy_b(i) = (cap*(1 - SOC_arrival_home_b(i)))/conversion_factor;
% Use required charging energy with charging power to determine required
% charging duration to reach a full charge (hour)
duration_charge_b(i) = charging_energy_b(i)/charging_power;
% Convert hours to full charge to minutes, and round
intervals_charge_b(i) = round((duration_charge_b(i)*(intervals/24)),0);
% Add charging power of each minute for each EV
if chargingstart_minute_b(i)+intervals_charge_b(i) > intervals
power_matrix_b(chargingstart_minute_b(i):end,i) = charging_power;
power_matrix_b(1:(chargingstart_minute_b(i)+intervals_charge_b(i)-intervals),i) = charging_power;
else
power_matrix_b(chargingstart_minute_b(i):chargingstart_minute_b(i)+intervals_charge_b(i),i) ...
= charging_power;
end
% Repeat loop for number of samples desired
i = i + 1;
end
% Total power for each minute
figure()
power_kw_b = sum(power_matrix_b,2);
power_Mw_b = power_kw_b/1000;
x(day)= plot(1:intervals,power_Mw_b)
xlabel('Time (minute)')
ylabel('Cumulative Load (MW)')
title(['Cumulative Load Over A Day in MW, ' num2str(samples) ' EVs'])
xlim([0 intervals])
hold on
end
hold off
0 个评论
回答(1 个)
Maria
2020-7-29
The easiest way wold be to just calculate the required load for the total of 7 days and store that data in one array. Then plot the whole week on one figure and edit the figure to add vertical axis to separate each day. It is similar to what you are doing now, but see that instead of plotting the data of each day, you need to plot the data of the 7 days altogether, so take the plotting function out of the 7 day loop and store the values of power_Mw_b for the whole week on one array. Hope this helps!
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!