How can I plot all these graphs using the if statement?
조회 수: 2 (최근 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!