title: sum 3dimensional matrix - Matlab Brute force
body: <p>Hi I have the 3 dimensional matrix in the code below. I am trying to sum all the 24 elements of "n" for every "number_panels" and "number_turbines" combination. </p>
  
  <p>what I have below doesn't sum across the 3rd dimension</p>
  
  <p>for number_panels = 0:5</p>
  
  <pre><code>for number_turbines = 0:2
  
      for n = 1:24 % number of hours per day
  
  
  
  hourly_deficit(number_panels + 1, number_turbines + 1, n) = Demand(n) -...     
  (PV_supply(n)*number_panels) - (WT_supply(n)*number_turbines);
  
  if hourly_deficit(number_panels + 1, number_turbines + 1, n)&lt; 0
  
              hourly_deficit(number_panels + 1, number_turbines + 1, n) = 0;
  
          end
  daily_deficit(number_panels + 1, number_turbines + 1) = sum(sum(sum(hourly_deficit(:,:,:)))) 
  
  
  
          hourly_total_RES(number_panels + 1, number_turbines + 1, n) = PV_supply(n)*number_panels + WT_supply(n)*number_turbines;
  
  
          if hourly_total_RES(number_panels + 1, number_turbines + 1, n) &lt; Demand(n),
  
              renewables_penetration(number_panels + 1, number_turbines + 1, n) = (hourly_total_RES(number_panels + 1, number_turbines + 1, n)) / Demand(n); % ratio of renewable energy supply to demand
  
          else
              renewables_penetration(number_panels + 1, number_turbines + 1, n) = 1 ;
  
          end
               peak_deficit(number_panels + 1, number_turbines + 1,n) = max(hourly_deficit(number_panels + 1, number_turbines + 1,n));
      end
  </code></pre>