title: Five dimensional matrix manipulation
body: <p>I have made the following changes to the code but still get the "Index exceeds matrix dimensions" error on the line where the "if statement" is called and I am for looping the "h" starting from 2:25. I still have net figured out how I can use an element from the previous dimension in the current dimension equation expression</p>
  
  <pre><code>  number_of_days = 3;
  number_of_hours = 24*number_of_days;
  number_panels = 1:5;
  
  
  for idx_number_panels = 1:length(number_panels) % range of PV panel units examined
  
  for number_turbines = 0:1 % range of wind turbine units examined
  
      for number_batteries = 1:2 % range of battery units examined
  
  
          for h=2:25 %# hours
                 battery_capacity(:,:,:,1,1) = max_battery_capacity*number_batteries;
  
              for d = 1:number_of_days %# which day
  
                  n = h + 24*(d-1);
  
  
  
                  if   (max_battery_capacity*number_batteries) - (battery_capacity(idx_number_panels, number_turbines+1 ,number_batteries, h-1,d)*number_batteries) &gt;0
  
                      storage_availability(idx_number_panels, number_turbines+1 ,number_batteries, h,d) =  (max_battery_capacity*number_batteries) - (battery_capacity(idx_number_panels, number_turbines+1 ,number_batteries, h-1,d)) ;
  
                  else
  
  
                      storage_availability(idx_number_panels, number_turbines+1 ,number_batteries, h,d) = 0;
  
  
                  end
  </code></pre>