필터 지우기
필터 지우기

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

조회 수: 1 (최근 30일)
Grigori
Grigori 2024년 2월 26일
편집: Torsten 2024년 2월 26일
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!

답변 (1개)

Walter Roberson
Walter Roberson 2024년 2월 26일
편집: Torsten 2024년 2월 26일
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