Azzera filtri
Azzera filtri

How to get daily average output for a week

3 visualizzazioni (ultimi 30 giorni)
Afnan Rahman
Afnan Rahman il 24 Lug 2020
Commentato: jonas il 27 Lug 2020
Hi,
I have coded the average daily output load demand of an EV for one day. I got the graph of load demand for whole 1440 minutes(i.e. one whole day). However, I am trying to use this code in aother loop to get an output load demand for a week.
I am unable to get any output yet. Was wondering if anyone can help me out here.
Thanks in advance.
Afnan Rahman
  3 Commenti
Afnan Rahman
Afnan Rahman il 27 Lug 2020
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;
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])
legend('Day 1')
hold on
end
jonas
jonas il 27 Lug 2020
Cannot test the code atm, but here is an idea.
If the loop works for several days, then you can just concatenate the output at the end of the second loop (where you plot). I would either append or save results for separate days in a cell array. To save as cell array
Results_all{day} = power_Mw_b

Accedi per commentare.

Risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Help Center e File Exchange

Tag

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by