How to make plot from if statement?
显示 更早的评论
% Hi I am really stuck and would very much appreciate help!
% I want to make a graph that looks like this:

% Here is my code:
x = linspace(-5,5,50);
if (x>-2 & x<0)
Y = x*1.5+3
elseif (x>0 & x<2)
Y = x*(-1.5) + 3
else
Y = 0
end
plot(x,Y)
% How can I plot this?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File 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!