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

12 views (last 30 days)
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)

Accepted Answer

Damien
Damien on 12 Oct 2016
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 Comments

Sign in to comment.

More Answers (0)

Categories

Find more on Line 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!