I am unable to solve this array dimensional error can someone help please?
Ältere Kommentare anzeigen
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!
Antworten (1)
Walter Roberson
am 26 Feb. 2024
Bearbeitet: Torsten
am 26 Feb. 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
Kategorien
Mehr zu Object Analysis finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!