MATLAB Answers

Using value from previous cell in for loop calculation

1 view (last 30 days)
Andrew Alkiviades
Andrew Alkiviades on 13 May 2012
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 Comments

Sign in to comment.

Answers (0)

Sign in to answer this question.


Translated by