필터 지우기
필터 지우기

start for loop from non zero value

조회 수: 2 (최근 30일)
Andrew Alkiviades
Andrew Alkiviades 2012년 7월 23일
Hi I am trying to run the code below for "number_panels" going from 1000 to 2000 with a step interval of 500. The below doesn't seem to work and was wondering if anyone knows how to modify this to get the required
my code is
number_of_days = 2;
for number_panels = 1000:500:2000 % range of PV panel units examined
for number_turbines = 0:1:3 % 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
As it stands i am getting size(hourly_deficit) = 2001 4 24 2
whereas I am expecting 3 4 24 2

채택된 답변

Doug Hull
Doug Hull 2012년 7월 23일
look at the value of number_panels on the very first time through the loops:
hourly_deficit(number_panels + 1, number_turbines + 1, h,d) =
or
hourly_deficit(1000 + 1), ...)
and on last time through:
hourly_defisit(2000 + 1), ...)
Similar things happen on the other indicies.
Maybe you want to have a iii = 0; outside the loop, and then
iii = iii+1;
inside the outer loop and index with it?
hourly_deficit(iii,...)

추가 답변 (1개)

Walter Roberson
Walter Roberson 2012년 7월 23일
panel_vals = 1000:500:2000;
for panel_number = 1 : length(panel_vals)
number_panels = panel_vals(panel_number);
[...]
hourly_deficit(panel_number, number_turbines + 1, h,d) = hourly_annual_demand(n) - (hourly_annual_PV(n)*number_panels) - (hourly_annual_WT(n)*number_turbines)
I am guessing here that the multiplication by number_panels should be the 1000, 1500, etc., the value rather than the index.

카테고리

Help CenterFile Exchange에서 Programming에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by