for loop and if else statement? it is not working with the different angle. could you please suggest me some solution
1 view (last 30 days)
Show older comments
Prakash Choudhary
on 3 May 2019
Answered: Walter Roberson
on 3 May 2019
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 Comments
Accepted Answer
Walter Roberson
on 3 May 2019
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 Comments
More Answers (0)
See Also
Categories
Find more on Discrete Data Plots in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!