For loop output into array

조회 수: 4 (최근 30일)
Joe Hunt
Joe Hunt 2021년 4월 29일
댓글: Joe Hunt 2021년 4월 29일
Hi guys, I'm really puzzled why I can't seem to get the outputs of my for loop into a 1 by 12 array? The for loop is working correctly but my final line of code in the loop which is intended to get the outputs into the annual_power array. Would really appreciate it if someone could point me in the right direction!
Note: I've tried refering to this link:
but still don't seem to be able to get it to work.
annual_power=zeros(1,12);
for i=[18.7633 19.5139 18.7633 15.0107 11.2580 10.5075 11.2580 13.5096 16.5117 17.2623 18.7633]
[power_25,speed_25] = floris(i,density,wind_direction,...
turbine_centres,yaw_angles,diameter,power_curve,location);
farm_power=sum(power_25);
annual_power(i)=farm_power(1);
end

답변 (1개)

David Hill
David Hill 2021년 4월 29일
annual_power=zeros(1,12);
ref=[18.7633 19.5139 18.7633 15.0107 11.2580 10.5075 11.2580 13.5096 16.5117 17.2623 18.7633];
for i=1:length(ref)
[power_25,speed_25] = floris(ref(i),density,wind_direction,...
turbine_centres,yaw_angles,diameter,power_curve,location);
farm_power=sum(power_25);
annual_power(i)=farm_power;
end
  댓글 수: 1
Joe Hunt
Joe Hunt 2021년 4월 29일
Thanks David I've got it working now! Much appreciated!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by