2012-02-02 206 views
0

他我正在使用来自三个厂家涡轮具体参数建模的风力涡轮机 我的代码工作是如果内的循环语句 - Matlab的

Site_speed = xlsread('test.xlsx','Sheet1'); % Wind speed data recorded on site 
air_density = xlsread('test.xlsx','Sheet2'); % Air density data recorded on site 

Turbine_parameters = xlsread('windparameters.xlsx'); % Wind turbine unit database 

Ref_wind_speed = Turbine_parameters(:,1); % Wind speed from wind turbine unit database file Turbine_parameters 
Ref_output = Turbine_parameters(:,2:4); % Power output from wind turbine unit database file Turbine_parameters 

Density_correct = (air_density./air_density_ref); 

for K = 1 : size(Ref_output, 2) 

    power_out(:,:,K) = Density_correct.* interp1(Ref_wind_speed, Ref_output(:,K), Site_speed, 'nearest'); 

% xlswrite('this_file2.xlsx', power_out(:,:,1), 'sheet1'); 
% xlswrite('this_file2.xlsx', power_out(:,:,2), 'sheet2'); 
% xlswrite('this_file2.xlsx', power_out(:,:,3), 'sheet3'); 

%% WIND TURBINE FINANCIAL ANALYSIS + OPERATIONAL EMISSIONS 

Array_supply(:,:,K) = (1-Losses) .* power_out(:,:,K) .* Turbines; 
Total_array(:,:,K) = sum(Array_supply(:)); 
Array_OM_cost(:,:,K) = sum(sum(Total_array(:,:,K) * Wind_OM)); 

% % Grid connected system with internal load 
end 

for K = 1 : size(Array_supply,3) 
    Demand = xlsread('demandtest.xlsx'); 
    if Demand >= Array_supply(:,:,K) 
     Grid(:,:,K) = Demand - Array_supply(:,:,K) 
     Income(:,:,K)= (Array_supply(:,:,K)*FIT_wind) + Array_supply(:,:,K)*Grid_cost); 
     Expences(:,:,K) = (Array_OM_cost(:,:,K)) + sum(sum((Grid(:,:,K)*Grid_cost))); 
     Profit(:,:,K) = sum(sum(Income(:,:,K))) - sum(sum(Expences(:,:,K))); 
    else 
     Income(:,:,K) = (Demand*FIT_wind) + (Demand*Xe_wind)+(Demand*Grid_cost); 
     Expences(:,:,K) = Array_OM_cost(:,:,K); 
     Profit(:,:,K) = sum(sum(Income(:,:,K))) - sum(sum(Expences(:,:,K))); 
    end 
end 

我已经证明上述所有的代码,但我认为错误从行开始 - 对于K = 1:size(Array_supply,3) 程序运行时得到的结果是一组三个矩阵(如预期的那样),其中前两个矩阵仅填充零(不正确) 。 此外,网格,收入和费用应该是365x 24矩阵(如需求和Array_supply) 当我尝试并运行网格(:,:,K)时,出现一个错误,说Matlab无法找到它!

有没有人有任何想法,我可能会出错? 谢谢

回答

1

首先,在Matlab中预先分配数组总是最好的做法。如果你知道网格,收入,费用和利润都将是一个365x24x3的矩阵,那么你应该把它放在循环之前,并且对其他变量也这样做。

Grid=zeros(365,24,3); 

至于你的问题,看起来你可能没有正确计算它。在Demand=xlsread(...)声明后放置一个断点。需求看起来是否正确?需求必须是一个单一的变量,如果它是一个矩阵,那么这就是你的问题。如果它是一个矩阵,则需要遍历每个变量。有更多优雅的解决方案涉及逻辑掩码,如果您愿意,随时查找概念。我会建议,至少在目前,你只需循环整个需​​求循环。

此外,我不认为你正确使用你的利润报表。它仅在每个循环中存储单个变量,但是您要为整个矩阵存储它......看起来Profit最好像3x1矩阵一样,引用它像Profit(f)而不是Profit(:, :,F)。

哦,还有一个非常小的一点,它是费用,不是费用...