MATLAB: How can i plot 5 periods of this signal

signal processing

hi, i have the following signal and i want to plot 5 cycles of it. but i'm getting an error
samples = 500;
T = 5;
f0 = 1/T;
t = linspace(0,T,samples+1); % 5 cycles
t(end) = [];
s2_hinf = exp(-((t-6)/4));
s2 = repmat(s2_hinf, [1 5]);
figure(1)
plot(t, s2);
but i'm getting the following error Error using plot Vectors must be the same length.

Best Answer

If you use repmat to concatenate the data 5 times, you have to concatenate the time t also 5 times, but add T in each block cumulatively:
samples = 500;
T = 5;
t = linspace(0,T,samples+1); % 5 cycles
t(end) = [];
s2_hinf = exp((6 - t) / 4);
s2 = repmat(s2_hinf, [1 5]);
t2 = reshape(t(:) + (0:T:4*T), 1, []); % >= Matlab R2016b
figure;
plot(t2, s2);
With older Matlab versions:
t2 = reshape(bsxfun(@plus, t(:), 0:T:4*T), 1, []);