Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8223645
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T14:46:46+00:00 2026-06-07T14:46:46+00:00

Hi I have the 3 dimensional matrix in the code below. I am trying

  • 0

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.

what I have below doesn’t sum across the 3rd dimension

for number_panels = 0:5

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)< 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) < 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
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T14:46:47+00:00Added an answer on June 7, 2026 at 2:46 pm

    In MATLAB sum(X) adds all elements of matrix X in one dimension.
    If you want to just calculate the sum for one specific dimension use:

     S1=sum(X,dimension);
    

    where “dimension” is 1, or 2, or 3 for a 3D matrix.

    If you want to compute over two dimensions then you can do:

     S2=sum(S1,dimension);
    

    where dimension here is 1, or 2.

    Based on your code I think this is what you should do if you want to do it in for loops:

    for number_panels = 0:5
       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)< 0
               hourly_deficit(number_panels + 1, number_turbines + 1, n) = 0;
          end
          daily_deficit(number_panels + 1, number_turbines + 1) = ...
            sum(hourly_deficit(number_panels + 1, number_turbines + 1,:));
        end
     end
    

    Look at the “:” that I added to:
    sum(hourly_deficit(number_panels + 1, number_turbines + 1,:));

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hi I have a 3 dimensional matrix that I am trying to convert the
I have a two dimensional array having elements of a matrix I want to
I have a bunch of values in a 3-dimensional matrix, and I am finding
I have got a matrix which gives me a 2-dimensional discrete distribution (N²->R) in
I have matrix with 3 dimension (n*m*k). I am trying to fined the maximum
The code below calculates the correlation matrix given a covariance matrix. How can I
my current code is below. What I have is two sets of data phi
I have a SquareMatrix template class which inherits Matrix template class, like below: SquareMatrix.h:
Well, Trying to do something with search engines. I have generated a matrix (term-document)
I have a large 4 dimensional matrix, and I wish to 1) find the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.