MATLAB: Why the square wave is just a line

signal processing

i'm trying to get a square wave graph for 5 cycles. but the plot is just a line
T = 2.25;
samples = 500;
t = linspace(-2.75,T,samples+1); % 5 cycles
t(end) = [];
s(-2.75 <= t < -0.25) = 1;
s(-0.25 <= t < 2.25) = -1;
N = 5;
s = repmat(s, [1 N]);
t = linspace(-2.75, N*T, N*samples + 1);
t(end) = [];
figure()
plot(t, s)
thanks

Best Answer

You can only do paired comparisons. Break the logic up into two separate conditions and it works:
s(-2.75 <= t & t < -0.25) = 1;
s(-0.25 <= t & t < 2.25) = -1;