for loop and if else statement? it is not working with the different angle. could you please suggest me some solution
4 次查看(过去 30 天)
显示 更早的评论
for i=1:size(angle)
if(angle(i) >= 1 || angle(i)<= 9)
v1(i) =v0(i)*(1-deficit1); %affected by the x away one% downstream wind for turbine 2nd
v2(i) =v1(i)*(1-deficit2); %affected by the x away one% downstream wind for turbine 2nd
v3(i) =v2(i)*(1-deficit3); %affected by the x away one% downstream wind for turbine 2nd
else
end
if(angle(i) >=10 || angle(i) <=170)
v1(i) =v0(i);
v2(i) =v0(i);
v3(i) =v0(i);
else
end
if(angle(i) >= 171 || angle(i)<= 189)
v1(i)=v0(i)*(1-deficit2); %affected by the x away one% downstream wind for turbine 2nd
v2(i)=v1(i)*(1-deficit1); %affected by the x away one% downstream wind for turbine 2nd
% v3(i)=v2(i)*(1-deficit3) %affected by the x away one% downstream wind for turbine 2nd
else
end
if(angle(i) >=190 || angle(i) <=350)
v1(i) =v0(i);
v2(i) =v0(i);
v3(i) =v0(i);
else
end
if(angle(i) >= 351 || angle(i)<= 360)
v1(i)=v0(i)*(1-deficit2); %affected by the x away one% downstream wind for turbine 2nd
v2(i)=v1(i)*(1-deficit1); %affected by the x away one% downstream wind for turbine 2nd
% v3(i)=v2(i)*(1-deficit3) %affected by the x away one% downstream wind for turbine 2nd
else
end
end
0 个评论
采纳的回答
Walter Roberson
2019-5-3
You should be using && rather than || for those tests.
Also remember that if you are dealing with floating point numbers, that (say) 9.2 is not <= 9 and is not >= 10 and so would not match any of your conditions.
if angle(i) < 1
ummm, what? angle is negative or between 0 and 1
elseif angle(i) < 10
1 inclusive to 10 exclusive case
elseif angle(i) < 170
10 inclusive to 170 exclusive case
elseif angle(i) <= 190
170 inclusive to 190 inclusive case
elseif angle(i) < 350
190 exclusive to 350 exclusive case
elseif angle(i) <= 360
350 inclusive to 360 inclusive case
else
ummm, what? angle is greater than 360 or is nan
end
0 个评论
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!