Borrar filtros
Borrar filtros

I am unable to solve this array dimensional error can someone help please?

1 visualización (últimos 30 días)
Grigori
Grigori el 26 de Feb. de 2024
Editada: Torsten el 26 de Feb. de 2024
n error occurred while running the simulation and the simulation was terminated
Caused by:
Index exceeds array dimensions. Index value 2 exceeds valid range [1-1] for array 'P_battery'. Code generation does not support growing arrays via indexing except by using end+1.
Error in 'vanadiummicrogrid/MATLAB Function' (line 13)
P_battery(i) = P_battery;
Here is my code
function P_battery = EMS(netP, soc)
soc_max = 95; % percent
battery_max = .116; %kW
for i=1:length(netP)
if netP(i) > 0 && soc < soc_max
P_battery = min(netP(i), battery_max);
else
P_battery = max(netP(i), battery_max);
end
P_battery(i) = P_battery;
end
Also can someone tell me whether this program is structured well? I just need it so if the power exceeds the need of the load then the power reroutes to the battery. Thank you!

Respuestas (1)

Walter Roberson
Walter Roberson el 26 de Feb. de 2024
Editada: Torsten el 26 de Feb. de 2024
function P_battery = EMS(netP, soc)
soc_max = 95; % percent
battery_max = .116; %kW
P_battery = zeros(1, length(netP));
for i=1:length(netP)
if netP(i) > 0 && soc < soc_max
P_bat = min(netP(i), battery_max);
else
P_bat = max(netP(i), battery_max);
end
P_battery(i) = P_bat;
end

Community Treasure Hunt

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

Start Hunting!

Translated by