Showing us some of your prior attempts would certainly help, since we then could avoid suggesting stuff you already tried.
Anyway, whenever I needed square waves, I used a sine wave together with logical operators, e.g.
f = @(t) (sin(2*pi*t)>0)-(sin(2*pi*t)<=0)
should get you a square wave with frequency 1. Adapt it to your needs.