If Statement within for loop - Matlab -



If Statement within for loop - Matlab -

him working on modelling wind turbine using turbine specific parameters 3 manufacturers code

site_speed = xlsread('test.xlsx','sheet1'); % wind speed info recorded on site air_density = xlsread('test.xlsx','sheet2'); % air density info recorded on site turbine_parameters = xlsread('windparameters.xlsx'); % wind turbine unit database ref_wind_speed = turbine_parameters(:,1); % wind speed wind turbine unit database file turbine_parameters ref_output = turbine_parameters(:,2:4); % powerfulness output wind turbine unit database file turbine_parameters density_correct = (air_density./air_density_ref); 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 scheme internal load end 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

i have shown of code above, think mistakes start @ line - k = 1 : size(array_supply,3) results when programme runs set of 3 matrices (as expected) first 2 populated zeros (incorrect). grid, income , expenses should 365x 24 matrices (as demand , array_supply) when seek , run grid(:,:,k), error appears saying matlab cant find it!!

does have thought might have gone wrong? thanks

first of all, best practice in matlab pre-allocate arrays. if ou know grid, income, expenses, , turn a profit going 365x24x3 matrix, should set before loop, , doing likewise other variables.

grid=zeros(365,24,3);

as problem, seems aren't computing correctly. set break point after demand=xlsread(...) statement. demand right? demand must single variable, if matrix, problem. if matrix, need loop through every variable. there more elegant solutions involving logical masks, sense free concept if want to. i'm going suggest @ to the lowest degree time being, loop through whole demand loop.

also, don't think using turn a profit statements correctly. storing single variable per loop, storing entire matrix... seems turn a profit served 3x1 matrix, referencing profit(f) instead of profit(:,:,f).

oh, , minor point, it's expenses, not expences...

matlab if-statement for-loop

Comments

Popular posts from this blog

How do I check if an insert was successful with MySQLdb in Python? -

delphi - blogger via idHTTP : error 400 bad request -

postgresql - ERROR: operator is not unique: unknown + unknown -