MATLAB: How to combine this functions and plot it

fourierMATLABperiodicplot

I need to combine this and th result has to be someting like that

Best Answer

Something like this
n = 0;
f1 = @(t) (0<(mod(t,3))&(mod(t,3)<=1)).*2.*(mod(t,3)-3*n);
f2 = @(t) (1<(mod(t,3))&(mod(t,3)<=2)).*2;
f3 = @(t) (2<(mod(t,3))&(mod(t,3)<=3)).*(mod(t,3)-3*(1+n)).^2;
f = @(t) f1(t) + f2(t) + f3(t);
t = linspace(0, 9);
y = f(t);
plot(t, y);