Using MATLAB to define a function in signal processing 101
Well, this is Octave but should work in Matlab:

function y=Y(t)
  y=ones(size(t));
  y=y+(t&lt;=0)*(-2);


.. and it is vectorised. Calling will look like:

&gt;t=linspace(-T,T,1000);
&gt;y=Y(t);


To make this more general we could also make the time at which the function switches a parameter also:

function y=Y(t,S)
  y=ones(size(t));
  y=y+(t&lt;=S)*(-2);