how to draw piecewise functions
Show older comments

hello, i need to draw the given piecewise function then calculate g(t+1), 3*g(t),etc but my code is unable to draw the function. it is not showing any graph, when i delete first function and write the lines separately it says it had to be inside of a function, if i put the first function at the bottom it gives the error of "not enough arguments".
function execute(~)
t= -4:0.01:10;
plot(t,g(t));
end
function y = g(t)
if t<-2
y=0;
elseif -2<t & t<0
y=-4-2*t;
elseif 0<t & t<4
y=-4+3*t;
elseif 4<t & t<8
y=16-2*t;
else
y=0;
end
end
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB 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!