For creating the rectangular pulse waveform, there is an inbuilt function phased.RectangularWaveform in Phased Array System Toolbox .You can try using that
waveform=phased.RectangularWaveform('PulseWidth',Ti,'PRF',1/T,'OutputFormat','Pulses','NumPulses',N);
y=waveform();
y=(b-a)*y;
du = N*1/waveform.PRF;
tsam = du*waveform.SampleRate;
t = unigrid(0,1/waveform.SampleRate,du,'[)');
plot(t.*1000,real(y)+a);
Refer to the below link for more information