Index exceeds matrix dimensions for 5 dimensional matrix

Hi I have the following code with the error "Index exceeds matrix dimensions" on the line of the "if statement" and I can't figure out why?!
My code is
for idx_number_panels = 1:length(number_panels)
for number_turbines = 1:2 % range of wind turbine units examined
for number_batteries = 1:10 % range of battery units examined
for h=2:25 %# hours
for d = 1:number_of_days %# which day
n = h + 24*(d-1);
hourly_surplus(idx_number_panels , number_turbines+1 ,number_batteries, h,d) = (hourly_total_RES(idx_number_panels,number_turbines + 1,number_batteries, h,d))-hourly_annual_demand(n);% hourly power deficit (RES supply with demand)
if hourly_surplus(idx_number_panels, number_turbines+1 ,number_batteries, h,d)< 0 % zero out negative hourly deficit values (this is power surplus from RES)
hourly_surplus(idx_number_panels, number_turbines+1 ,number_batteries, h,d) = 0;
battery_position(idx_number_panels, number_turbines+1 ,number_batteries, h,d) = 0;
input_energy_flow(idx_number_panels, number_turbines+1 ,number_batteries, h,d) = 0;
output_energy_demand(idx_number_panels, number_turbines+1 ,number_batteries, h,d) =hourly_deficit(idx_number_panels, number_turbines+1 ,number_batteries, h,d) ;
else
battery_position(idx_number_panels, number_turbines+1 ,number_batteries, h,d) = 1;
input_energy_flow(idx_number_panels, number_turbines+1 ,number_batteries, h,d) = hourly_surplus(idx_number_panels, number_turbines+1 ,number_batteries, h,d) ;
end
battery_capacity(:, : ,:, 1,1) = 2*number_batteries;
if (max_battery_capacity*number_batteries) - (battery_capacity(idx_number_panels, number_turbines+1 ,number_batteries, h-1,d)) >0
storage_availability(idx_number_panels, number_turbines+1 ,number_batteries, h,d) = maybe(idx_number_panels, number_turbines+1 ,number_batteries, h,d) else
storage_availability(idx_number_panels, number_turbines+1 ,number_batteries, h,d) = 0;
end

2 commentaires

Which line is the error on?
the error is on the if statement
if (max_battery_capacity*number_batteries) - (battery_capacity(idx_number_panels, number_turbines+1 ,number_batteries, h-1,d)) >0

Connectez-vous pour commenter.

Réponses (1)

dbstop if error
Then run the code using the play button or from the command line. It will stop with the debugger on the offending line with the offensive variables so you can figure out what's wrong.

6 commentaires

thanks I get the same error on the command line Index exceeds matrix dimensions. if (max_battery_capacity*number_batteries) - (battery_capacity(idx_number_panels, number_turbines+1 ,number_batteries, h-1,d)) >0
now type
sz = size(battery_capacity)
index = [idx_number_panels, number_turbines+1 ,number_batteries, h-1,d]
Whichever index is greater than sz, that's your problem.
Sean do you see anything in my indexing that should pop up this error?
No. But I have no idea what your variables are. I think Jonathan's approach here is the right one. It stops on that line - inspect every variable and command used on that line to investigate. For example if I had:
y = f(x(ii+1))+k(ii)
I would run:
k(ii)
x(ii+1)
f(x(ii+1))
%etc.
Thanks I get all sizes as a 1 and so is the "sz" . The day "d" which is the fifth dimension is a 2. I don't see how I can do anything about this
if I change the " for number_turbines " loop on the second line of my code to start from zero then the error is on the fifth dimension. If I have the "for number_turbines" loop starting from 1 then I have the error on the second dimension i.e the "number_turbines".

Connectez-vous pour commenter.

Catégories

Community Treasure Hunt

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

Start Hunting!

Translated by