How do i graph various conditions in MATLAB
조회 수: 1 (최근 30일)
이전 댓글 표시
So heres my issue. I have specific conditions. So lets say I want to graph the function y=0.005*x at x<=2000. But. At 2000<x<2500 y=10-0.02*x, and if x>2500, then y=0. I have been doing if and elseif but my graph only shows the first condition. Can you help me with the code?
댓글 수: 0
답변 (1개)
Mark Sherstan
2019년 2월 10일
You can give the code below a try or post your own code so we can help you with your train of thought.
x = 1:4000;
y = zeros(length(x));
for ii = 1:length(x)
if x(ii)<=2000
y(ii) = 0.005*x(ii);
elseif (2000<x(ii) && x(ii)<2500)
y(ii) = 10-0.02*x(ii);
elseif x(ii)>2500
y(ii) = 0;
else
fprintf("Error at %0.f\n",x(ii));
end
end
plot(x,y)
댓글 수: 0
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!