How can I plot all these graphs using the if statement?
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
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
Damien
on 12 Oct 2016
Sure, just create different variables or something like that:
plot(d(1:50),e(1:50));
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D 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!