How can I plot all these graphs using the if statement?

3 次查看(过去 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)

采纳的回答

Damien
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)

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by