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

  • Home
  • SEARCH
  • 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 8265787
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T04:55:39+00:00 2026-06-08T04:55:39+00:00

I have the code below in which I am trying to start the number_panels

  • 0

I have the code below in which I am trying to start the “number_panels” and “number_turbines” for loop from a non zero number.

More specifically I am trying for 3000 to 4000 “number_panels” with 500 panel interval
and from 5 to 8 “number_turbines” with one turbine interval
i.e

number_of_days = 2;

for number_panels = 3000:500:4000 % range of PV panel units examined

for number_turbines = 5:8  % range of wind turbine units examined


    for h=1:24 %# hours

       for d = 1:number_of_days %# which day



            n = h + 24*(d-1);
            % hourly_deficit_1(...,..., h, d)= Demand(n)-(PV_supply(n)... %


            hourly_deficit(number_panels + 1, number_turbines + 1, h,d) = hourly_annual_demand(n) - (hourly_annual_PV(n)*number_panels) - (hourly_annual_WT(n)*number_turbines);% hourly power deficit (RES supply with demand)


            if hourly_deficit(number_panels + 1, number_turbines + 1, h,d)< 0 % zero out negative hourly deficit values (this is power surplus from RES)

                hourly_deficit(number_panels + 1, number_turbines + 1, h,d) = 0;

            end

When I do this I get a size(hourly_deficit) = 4001,9,24,2 whereas I am expecting and trying to achieve a 3,4,24,2 size. Does anyone know where I am going wrong?

  • 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-08T04:55:41+00:00Added an answer on June 8, 2026 at 4:55 am

    The value of the variable number_panels starts at 3000 instead of 0 or 1. Thus when you index a matrix with that variable as the index value Matlab thinks you are wanting the 3001st index and thus gives you a matrix that is 3000 zeros with the 3001st being set to what you ask.

    If you follow the loop into it’s next cycle the value of number_panels becomes 3500. You now are indexing at 3501, based on your code. This means that all of the places from 3002 to 3500 will be filled with zeros and 3501 will be set to whatever value you give it.

    The same logic applies to number_turbines The only difference is that you’ll be indexing by 1 instead of by 500 like you are with number_panels.

    If you want to get back to the size matrix you are expecting you’ll need to modify the way you call the index values. This could be done a number of ways. You could have a counter within the for-loop or you could use modulus math. Modulus math doesn’t work well when you’re using a step size that isn’t 1. It also doesn’t work when you get to the point where you have an index value that is a multiple of your starting index.

    You’ll have to work out what will work best for you in that arena. Especially since you want to use a step size that isn’t 1. But for the number_turbines that goes from 5 to 8, you can simple index using number_turbines - 5 + 1 or more concise number_turbines-4.

    For clarity, here is the code you provided with the necessary tweaks to show the use of what was mentioned in the comments. Please take note that you will need to modify the -4 for the number_turbines index value should you start at something other than 5. Also note that you need to index the number_panels vector now since it’s not a looped value.

    Hope this helps!

    number_of_days = 2;
    number_panels = 3000:500:4000;
    
    for idx_number_panels = 1:length(number_panels) % range of PV panel units examined
    
        for number_turbines = 5:8  % range of wind turbine units examined
    
    
            for h=1:24 %# hours
    
                for d = 1:number_of_days %# which day
    
    
    
                    n = h + 24*(d-1);
                    % hourly_deficit_1(...,..., h, d)= Demand(n)-(PV_supply(n)... %
    
    
                    hourly_deficit(idx_number_panels , number_turbines -4, h,d) = hourly_annual_demand(n) - (hourly_annual_PV(n)*number_panels(idx_number_panels)) - (hourly_annual_WT(n)*number_turbines);% hourly power deficit (RES supply with demand)
    
    
                    if hourly_deficit(idx_number_panels, number_turbines -4, h,d)< 0 % zero out negative hourly deficit values (this is power surplus from RES)
    
                        hourly_deficit(idx_number_panels, number_turbines -4, h,d) = 0;
    
                    end
                end
            end
        end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C extension (code below) in which I'm trying to get access
I have wrote the code below which was taken from Java How to program
I have a function(please see code below) which reads some data from the web.
I have a piece of matlab code below which reads data from a table.
I am trying to get values from a view which i have the code
I have a piece of code below which I am trying to use to
I have the code below which I use clone() and live() . The code
I have the code below which I use clone() and delegate() . The code
I have the following code below which works, but I want to insert values
I have below code which overrides equals() and hashcode() methods. public boolean equals(Object obj)

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.