This is not your function, however it illustrates the ‘logical indexing’ approach to such problems:
f = @(x) (2-2*x).*(x <= 0) + (2+2*x).*(x>0);
t = linspace(-3, 3);
figure
plot(t, f(t))
grid
ylim([0 max(ylim)])
Run it and view the plot it produces.
It is not difficult to figure out how it works. Be inspired by it!