Make one period, then use repmat() to replicate as many times as you want.
onePeriod = 1000 * [ones(1, 100), zeros(1, 100)];
dt = 0.1 / numel(onePeriod);
numCycles = 10;
fullWaveForm = repmat(onePeriod, [1, numCycles]);
t = dt * (0 : (numel(fullWaveForm) - 1));
plot(t, fullWaveForm, 'b-', 'LineWidth', 2);
FontSize = 20;
xlabel('Time (seconds)', 'FontSize', FontSize);
ylabel('Amplitude', 'FontSize', FontSize);
title('Square Wave With 10 Cycles', 'FontSize', FontSize);
grid on;
Best Answer