- Memory allocation for Battery_capacity, e.g., Battery_capacity = zeros(365,24)
- Initialization: Battery_capacity(:,1) = 100 (assuming for all i=1 the capacity is 100)
- For loops for j=1:365 and i=2:24, then it is possible to use Battery_capacity(j,i-1)
Using value from previous cell in for loop calculation
2 ビュー (過去 30 日間)
古いコメントを表示
Hi, I am trying to perform a set of calculations shown in the code below. I am trying to create a 365x24 matrix to find the "battery_capacity". This calculation requires knowledge of the number in the previous cell and thats why I have used (j,i-1) format which doesn't work. Also, I know that the starting value of battery capacitance (at position 1,1 in the matrix is 100. Does anyone know how I can change this code so that I can start from 1,2 to 365,24 using the previous cell value of capacity each time?
Thanks
for j = 1:365
for i = 1:24
if Total_hourly_RES(j,i) > Hourly_power_demand(j,i), % Charge batterys
Battery_capacity(1,1) = 100; %%Find capacity of typcial Pb-acid battery used in this type of system
Battery_capacity(j,i) = Battery_capacity(j,i-1)*(1-battery_self_discharge)+(Total_hourly_RES(j,i)-(Hourly_power_demand(j,i)).*battery_charging_efficiency) ; % Available battery bank capacity
if SOC_min*Battery_capacity(j,i) <= Battery_capacity(j,i), Battery_capacity(j,i) = SOC_min*Battery_capacity(j,i) ;
if SOC_max*Battery_capacity(j,i) >= Battery_capacity(j,i), Battery_capacity(j,i) = SOC_max*Battery_capacity(j,i) ;
end
end
else % Discharge battery
Battery_capacity(1,1) = 100; %%Find capacity of typcial Pb-acid battery used in this type of system
Battery_capacity(j,i) = Battery_capacity(j,i-1).*(1-battery_self_discharge)-(Hourly_power_demand(j,i)-Total_hourly_RES(j,i)).*battery_discharging_efficiency; % Available battery bank capacity
if SOC_min*Battery_capacity <= Battery_capacity(j,i), Battery_capacity(j,i) = SOC_min*Battery_capacity(j,i) ;
if SOC_max*Battery_capacity >= Battery_capacity(j,i); Battery_capacity(j,i) = SOC_min*Battery_capacity(j,i) ;
end
end
end
end
end
0 件のコメント
回答 (1 件)
Sabin
2023 年 10 月 3 日
The steps to to this:
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!