How can I plot all these graphs using the if statement?
1 次查看(过去 30 天)
显示 更早的评论
d=-26.5:1:1973.5;
if (0 < d) & (d <=52)
e = d*0.05;
elseif (d > 1000)
e = d*0.45-130.5;
elseif (440 < d <=1000)
e = d*0.40-80.5;
elseif (235 < d <=440)
e = d*0.30-36.5;
elseif (117 <d) & (d<=235)
e =d*0.20-13;
else (52< d) & (d<117)
e =d*0.12-3.64;
end
plot(d,e)
0 个评论
采纳的回答
Damien
2016-10-12
Hello, Your variable e should be a vector. I will try with a for loop
for i = 1:2001
d(i)=i-27.5;
if (0 < d(i)) & (d(i) <=52)
e(i) = d(i)*0.05;
elseif (d(i) > 1000)
e(i) = d(i)*0.45-130.5;
elseif (440 < d(i) <=1000)
e(i) = d(i)*0.40-80.5;
elseif (235 < d(i) <=440)
e(i) = d(i)*0.30-36.5;
elseif (117 <d(i)) & (d(i)<=235)
e(i) =d(i)*0.20-13;
else (52< d(i)) & (d(i)<117)
e(i) =d(i)*0.12-3.64;
end
end
plot(d,e)
3 个评论
Damien
2016-10-12
Sure, just create different variables or something like that:
plot(d(1:50),e(1:50));
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!