嗨,我有这段代码,它不断给我一个“索引超出矩阵尺寸”错误。我试图用“battery_capacity”矩阵=2的值来启动h=1、d=1、24“h”和3“d”的循环,但这似乎与矩阵大小相矛盾。任何帮助表示赞赏!“h-1”是否会导致问题。错误出现在第二次写入“battery_capacity”我的代码是针对 idx_number_panels = 1:length(number_panels) % range of PV panel units 检查
for number_turbines = 0:2 % range of wind turbine units examined
for number_batteries = 1:50 % range of battery units examined
for h=2:25 %# hours
for d = 1:number_of_days %# which day
battery_capacity(idx_number_panels, number_turbines+1, ...
number_batteries, 1, 1) = 2*number_batteries;
%% Charging
battery_charging(idx_number_panels, number_turbines+1, ...
number_batteries, h, d) ...
= hourly_surplus(idx_number_panels, number_turbines+1, ...
number_batteries, h, d) ...
+ battery_capacity(idx_number_panels, number_turbines+1, ...
number_batteries, h-1,d);
end
end
end
调试器
error line 134
battery_charging(idx_number_panels, number_turbines+1 ,number_batteries, h,d) = hourly_surplus(idx_number_panels, number_turbines+1 ,number_batteries, h,d)...
K>> sz = size(battery_charging)
sz =
1 1 1 2
K>> index = [idx_number_panels, number_turbines+1 ,number_batteries, h-1,d]
index =
1 1 1 1 2
K>> ndims(battery_charging)
ans =
4
在命令行中运行“battery_charging”
>> battery_charging
battery_charging(:,:,1,1) =
0
battery_charging(:,:,1,2) =
0