dt=0.1; x=-10:dt:10; l=length(x); T=2; y=zeros(1,l); for i=1:l y(i)=i-round(round(i/(T/dt))*(T/dt)); end plot(x,y)